This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Convert decimal number to character vector representing hexadecimal number


str = dec2hex(d)
str = dec2hex(d, n)


str = dec2hex(d) returns the hexadecimal representation of d as a character vector. d must be a nonnegative integer. If d is an integer greater than the value returned by flintmax, then dec2hex might not return an exact representation. MATLAB® converts noninteger inputs, such as those of class double or char, to their integer equivalents before converting to hexadecimal.

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


To convert decimal 1023 to hexadecimal,

ans =

dec2hex(1023, 6)
ans =

Convert 2-by-5 array A to hexadecimal:

A = [3487,    125,  8997,  1433,  189; ...
      771,  84832,   118,  9366,  212];

 A(:)                    dec2hex(A)
ans =                    ans =
     3487                   00D9F
      771                   00303
      125                   0007D
    84832                   14B60
     8997                   02325
      118                   00076
     1433                   00599
     9366                   02496
      189                   000BD
      212                   000D4

Extended Capabilities