
| Function category | Engineering functions |
| Volatility | Non-volatile |
| Similar functions | BIN2DEC, 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)
| A | B | C | D | |
|---|---|---|---|---|
| 1 | R | G | B | Hex color |
| 2 | 255 | 99 | 71 | #FF6347="#"&DEC2HEX(A2,2)&DEC2HEX(B2,2)&DEC2HEX(C2,2) |
| 3 | 0 | 128 | 128 | #008080="#"&DEC2HEX(A3,2)&DEC2HEX(B3,2)&DEC2HEX(C3,2) |
| 4 | 30 | 144 | 255 | #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)
| A | B | C | |
|---|---|---|---|
| 1 | Decimal | Places | DEC2HEX |
| 2 | 255 | FF=DEC2HEX(A2) | |
| 3 | 16 | 4 | 0010=DEC2HEX(A3,B3) |
| 4 | -100 | FFFFFFFF9C=DEC2HEX(A4) | |
| 5 | -1 | FFFFFFFFFF=DEC2HEX(A5) | |
| 6 | 1000000 | 8 | 000F4240=DEC2HEX(A6,B6) |
| 7 | 255 | 1 | #NUM!=DEC2HEX(A7,B7) |
| 8 | 549755813888 | #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.