Main Content

dec2hex

Convert symbolic integer in decimal to hexadecimal representation

Description

example

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.

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 = 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)

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

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