Skip to Main Content Skip to Search
Product Documentation

dec2hex - Convert decimal to hexadecimal number in string

Syntax

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

Description

str = dec2hex(d) converts the decimal integer d to its hexadecimal representation stored in a MATLAB string. d must be a nonnegative integer smaller than 2^52. 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.

Examples

To convert decimal 1023 to hexadecimal,

dec2hex(1023)
ans =
    3FF

dec2hex(1023, 6)
ans =
0003FF

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

See Also

dec2bin | format | hex2dec | hex2num

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS