Features of !SEMTools
↑ Навигация по задачам в Excel и возможностям надстройки !SEMTools ↑

DEC2HEX

DEC2HEX function in Excel - decimal to hexadecimal conversion examples
Examples of using the DEC2HEX function
Function categoryEngineering functions
VolatilityNon-volatile
Similar functionsBIN2DEC, DEC2BIN, HEX2DEC

What does the DEC2HEX function do?

This function converts a decimal number to its hexadecimal equivalent.

It can only accept numbers from -549,755,813,888 to 549,755,813,887.

The result can be padded with leading zeros using an optional parameter, which is ignored for negative numbers.

DEC2HEX function syntax

=DEC2HEX(decimal_number, [places])
  • decimal_number — required. The decimal integer you want to convert
  • places — optional. The number of characters to use. If omitted, uses the minimum number necessary

DEC2HEX formula examples

Convert decimal 255 to hexadecimal:

=DEC2HEX(255)

Result: "FF"

Convert decimal 16 to hexadecimal with 4 characters:

=DEC2HEX(16, 4)
RGB → hex color code
D2="#"&DEC2HEX(A2,2)&DEC2HEX(B2,2)&DEC2HEX(C2,2)
ABCD
1RGBHex color
22559971#FF6347="#"&DEC2HEX(A2,2)&DEC2HEX(B2,2)&DEC2HEX(C2,2)
30128128#008080="#"&DEC2HEX(A3,2)&DEC2HEX(B3,2)&DEC2HEX(C3,2)
430144255#1E90FF="#"&DEC2HEX(A4,2)&DEC2HEX(B4,2)&DEC2HEX(C4,2)

With places = 2, each channel always takes two characters (0 → 00, 128 → 80), so the code is always 6 characters long.

Result: "0010"

Convert negative decimal number:

=DEC2HEX(-100)
DEC2HEX: padding, negatives, limits
C4=DEC2HEX(A4)
ABC
1DecimalPlacesDEC2HEX
2255FF=DEC2HEX(A2)
31640010=DEC2HEX(A3,B3)
4-100FFFFFFFF9C=DEC2HEX(A4)
5-1FFFFFFFFFF=DEC2HEX(A5)
610000008000F4240=DEC2HEX(A6,B6)
72551#NUM!=DEC2HEX(A7,B7)
8549755813888#NUM!=DEC2HEX(A8)

Negative numbers always come out as 10 hex characters: −1 is FFFFFFFFFF. Places pads positive results with zeros; too few places, or a number above 549,755,813,887, gives #NUM!.

Result: "FFFFFFFF9C" — 10 characters (40 bits) in two’s complement

DEC2HEX features and limitations

  • Negative numbers are represented using two's complement notation
  • The places parameter is ignored for negative numbers
  • If places is too small, returns the #NUM! error
  • If decimal_number is less than -549,755,813,888 or greater than 549,755,813,887, returns the #NUM! error
  • If decimal_number is nonnumeric, returns the #VALUE! error
  • If places is nonnumeric, returns the #VALUE! error
  • If places is not an integer, it is truncated

Other Engineering functions in Excel

BIN2DEC, BIN2HEX, CONVERT, DEC2BIN, DEC2OCT, DELTA, GESTEP, HEX2BIN, HEX2DEC, OCT2DEC

Like the article? Help its author! Buy !SEMTools, it has lots of useful instruments to process text data.