DEC2HEX Function
Converts a decimal number to hexadecimal.
Category
Engineering
Available in
All versions, Microsoft 365
Returns
Hexadecimal text (up to 10 characters)
Overview
DEC2HEX converts a decimal number into hexadecimal. Decimal (base 10) is the everyday number system. Hexadecimal (base 16) uses 0–9 and then A–F for 10–15.
The input must be from −549,755,813,888 to 549,755,813,887, or DEC2HEX returns #NUM!. Negative numbers use a fixed 10-character form called two's complement: the first digit acts as the minus sign. For example −1 is 1111111111 in binary, 7777777777 in octal and FFFFFFFFFF in hex.
Syntax
Arguments
| Argument | Required? | What it does |
|---|---|---|
| number | Yes | The whole number to convert, from −549,755,813,888 to 549,755,813,887. Any decimal part is dropped (3.9 is treated as 3). |
| places | No | How many characters to show, padding with leading zeros (e.g. 8 turns 101 into 00000101). Ignored for negative numbers. |
Examples
Example 1 — Decimal to hexadecimal
Each row converts the value in column A.
| A | B | |
|---|---|---|
| 1 | Decimal | Hex |
| 2 | 255 | FF |
| 3 | 100 | 64 |
| 4 | 4096 | 1000 |
| 5 | -54 | FFFFFFFFCA |
Example 2 — Build web colour codes from RGB values
Each colour channel (0–255) becomes two hex characters. Places = 2 keeps the leading zero.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Red | Green | Blue | Colour |
| 2 | 44 | 209 | 164 | #2CD1A4 |
| 3 | 255 | 255 | 255 | #FFFFFF |
| 4 | 17 | 24 | 39 | #111827 |
| 5 | 0 | 0 | 0 | #000000 |
Common mistakes
- #NUM! The number is outside −549,755,813,888 to 549,755,813,887, or places is too small to fit the answer (DEC2BIN(9,2) — 9 needs four binary digits).
Notes
- The answer is text, so it keeps leading zeros. Convert back with the matching ...2DEC function before doing maths with it.
- Related functions: HEX2DEC, DEC2BIN, DEC2OCT, BASE.

Author
Kyle Stott
Certified Microsoft Excel Expert
Kyle has worked professionally with Microsoft Excel for over a decade and has consulted on and taught Excel best practices to over 400 companies across 30+ countries.