Main Content


Convert symbolic integer in decimal to hexadecimal representation



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

If d is a matrix or multidimensional array of symbolic integers 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.


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


collapse all

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

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

Convert the decimal number to hexadecimal representation.

str = dec2hex(d)
str = 

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

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


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

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

str = dec2hex(d,4)
str = 4x4 char array

Input Arguments

collapse all

Integers in decimal representation, specified as a symbolic number, vector, matrix, or array.

In R2023a: d can include negative integers. The function converts negative integers using their two's complement binary values.

Example: sym([2 4])

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

Example: 8

Version History

Introduced in R2019a

See Also

External Websites