Main Content

dec2hex

Convert decimal number to character vector representing hexadecimal number

Description

example

str = dec2hex(d) returns the hexadecimal representation of symbolic number d as a character vector. d must be a nonnegative integer.

If d is a matrix or multidimensional array of symbolic numbers with N elements, dec2hex returns a character array with N rows. Each row of the output str corresponds to an element of d accessed with linear indexing.

example

str = dec2hex(d,n) returns a hexadecimal representation with at least n digits.

Examples

collapse all

Define a large integer 260-1 as a symbolic number.

d = sym(2)^60 - 1
d = 1152921504606846975sym('1152921504606846975')

Convert the decimal number to hexadecimal representation.

str = dec2hex(d)
str = 
'FFFFFFFFFFFFFFF'

Create a 2-by-2 symbolic matrix that contains integers in decimal representation.

d = [sym(2)^6 123; 54 11]
d = 

(641235411)[sym(64), sym(123); sym(54), sym(11)]

Convert the integers to hexadecimal representation using dec2hex. dec2hex returns 4 rows of character vectors. Each row contains a 2-digit hexadecimal number.

str = dec2hex(d)
str = 4x2 char array
    '40'
    '36'
    '7B'
    '0B'

Return a hexadecimal representation with at least 4 digits by specifying the number of digits.

str = dec2hex(d,4)
str = 4x4 char array
    '0040'
    '0036'
    '007B'
    '000B'

Input Arguments

collapse all

Decimal number, specified as a symbolic number, vector, matrix, or array. d must be a nonnegative integer.

Example: sym([2 4])

Number of hexadecimal digits, specified as a scalar positive integer.

Example: 8

See Also

Introduced in R2019a