Main Content


Convert number to hexadecimal equivalent using quantizer object



y = num2hex(q,x) converts numeric matrix x into a hexadecimal string returned in y. The attributes of the number are specified by the quantizer object q.

[y1,y2,…] = num2hex(q,x1,x2,…) converts numeric matrices x1, x2, … to hexadecimal strings y1, y2, ….


collapse all

Use num2hex to convert a matrix of numeric values to hexadecimal representation.

Convert Floating-Point Values

This is a floating-point example using a quantizer object 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

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

Input Arguments

collapse all

Attributes of the number, specified as a quantizer object.

Numeric values to convert, specified as a scalar, vector, matrix, multidimensional array, or cell array of doubles.

Data Types: double | cell
Complex Number Support: Yes

Output Arguments

collapse all

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.


  • num2hex and hex2num are inverses of each other, except that hex2num returns the hexadecimal values in a column.


  • For fixed-point quantizer objects, the representation is two's complement.

  • For floating-point quantizer objects, the representation is IEEE® Standard 754 style.

    For example, for q = quantizer('double'):

    q = quantizer('double');
    ans =

    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 =

    Sign bit is 0, exponent bits are all 1, and all fraction bits are 0.

    ans =

    Sign bit is 1, exponent bits are all 1, and all fraction bits are 0.

Version History

Introduced before R2006a