Main Content

dec2hex

Convert decimal integer to its hexadecimal representation for fi objects

Since R2021b

Description

hexStr = dec2hex(D) returns the hexadecimal, or base-16, representation of the decimal integer D. The output argument hexStr is a character array where each row represents the hexadecimal digits of each decimal integer in D using the characters 0-9 and A-F. D must contain finite integers.

example

hexStr = dec2hex(D,minDigits) returns a hexadecimal representation with no fewer than minDigits digits.

Tip

dec2hex returns the hexadecimal representation of the real-world value of the fi object D. To obtain the hexadecimal representation of the stored integer value, use hex instead.

example

Examples

collapse all

Convert the decimal number stored as a fi object to hexadecimal representation.

D1 = fi(2748);
D2 = fi(251);
hexStr1 = dec2hex(D1)
hexStr2 = dec2hex(D2)
hexStr1 =

    'ABC'


hexStr2 =

    'FB'

The dec2hex function converts negative numbers using their two's complement binary values.

D3 = fi(-5);
hexStr3 = dec2hex(D3)
hexStr3 =

    'FB'

Convert the decimal number stored as a fi object to hexadecimal representation. Specify the minimum number of hexadecimal digits that dec2hex returns. If you specify more digits than are required, then dec2hex pads the output.

D = fi(2748);
hexStr = dec2hex(D,8)
hexStr =

    '00000ABC'

If you specify fewer digits, then dec2hex still returns as many hexadecimal digits as required to represent the input number.

hexStr = dec2hex(D,2)
hexStr =

    'ABC'

Create a numeric fi array.

D = fi([1023 122 14]);

To represent the elements of D as hexadecimal values, use the dec2hex function. Each row of hexStr corresponds to an element of D.

hexStr = dec2hex(D)
hexStr =

  3×3 char array

    '3FF'
    '07A'
    '00E'

Convert a numeric fi array containing negative values and specify minimum number of digits.

D = fi([1023 122 14;2748 251 -5]);
hexStr = dec2hex(D,5)
hexStr =

  6×5 char array

    '003FF'
    '00ABC'
    '0007A'
    '000FB'
    '0000E'
    'FFFFB'

Convert the upper and lower bound of a signed fi object with 100-bit word length.

binStr = dec2hex([lowerbound(fi([],1,100,0)),...
    upperbound(fi([],1,100,0))])
binStr =

  2×25 char array

    '8000000000000000000000000'
    '7FFFFFFFFFFFFFFFFFFFFFFFF'

Input Arguments

collapse all

Input array, specified as a numeric fi array.

  • D must contain finite integers. If any element of D has a fractional part, then dec2hex produces an error. For example, dec2hex converts fi(10) to 'A', but does not convert fi(10.5).

  • D can include negative numbers. The function converts negative numbers using their two's complement binary values.

Data Types: fi

Minimum number of digits in the output, specified as a positive integer.

  • If D can be represented with fewer than minDigits hexadecimal digits, then dec2hex pads the output.

  • If D is so large that it must be represented with more than minDigits digits, then dec2hex returns the output with as many digits as required.

Extended Capabilities

Version History

Introduced in R2021b

See Also

| | | | | |