Convert number to hexadecimal equivalent using
num2hex to convert a matrix of numeric values to hexadecimal representation.
Convert Floating-Point Values
This is a floating-point example using a
q that has a 6-bit word length and a 3-bit exponent length.
x = magic(3); q = quantizer('float',[6 3]); y = num2hex(q,x)
y = 9x2 char array '18' '12' '14' '0c' '15' '18' '16' '17' '10'
Convert Fixed-Point Values
All of the 4-bit fixed-point two's complement numbers in fractional form are given by:
q = quantizer([4 3]); x = [0.875 0.375 -0.125 -0.625 0.750 0.250 -0.250 -0.750 0.625 0.125 -0.375 -0.875 0.500 0 -0.500 -1.000]; y = num2hex(q,x)
y = 16x1 char array '7' '6' '5' '4' '3' '2' '1' '0' 'f' 'e' 'd' 'c' 'b' 'a' '9' '8'
q— Attributes of the number
Attributes of the number, specified as a
x— Numeric values to convert
Numeric values to convert, specified as a scalar, vector, matrix, multidimensional array, or cell array of doubles.
Complex Number Support: Yes
y— Hexadecimal strings
Hexadecimal strings, returned as a column vector. If
x is a cell
array containing numeric matrices, then
y is returned as a cell array
of the same dimension containing hexadecimal strings.
hex2num are inverses of each other, except that
returns the hexadecimal values in a column.
quantizer objects, the representation is two's
quantizer objects, the representation is
IEEE® Standard 754 style.
For example, for
q = quantizer('double'):
q = quantizer('double'); num2hex(q,nan)
ans = 'fff8000000000000'
The leading fraction bit is 1, and all the other fraction bits are 0. Sign bit is 1, and exponent bits are all 1.
ans = '7ff0000000000000'
Sign bit is 0, exponent bits are all 1, and all fraction bits are 0.
ans = 'fff0000000000000'
Sign bit is 1, exponent bits are all 1, and all fraction bits are 0.