DEC2HEX Function

Converts a decimal number to hexadecimal.

Category

Engineering

Available in

All versions, Microsoft 365

Returns

Hexadecimal text (up to 10 characters)

Want to practice DEC2HEX in a real spreadsheet? Open a blank sheet in our Practice Sandbox and try it with live data, with the AI Excel tutor beside you. No Excel needed — just a free account.Try it free in the Sandbox

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

=DEC2HEX(number, [places])

Arguments

ArgumentRequired?What it does
numberYesThe 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).
placesNoHow 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.

B2fx=DEC2HEX(A2)
AB
1DecimalHex
2255FF
310064
440961000
5-54FFFFFFFFCA
=DEC2HEX(A2) Explain

Example 2 — Build web colour codes from RGB values

Each colour channel (0–255) becomes two hex characters. Places = 2 keeps the leading zero.

D2fx="#"&DEC2HEX(A2,2)&DEC2HEX(B2,2)&DEC2HEX(C2,2)
ABCD
1RedGreenBlueColour
244209164#2CD1A4
3255255255#FFFFFF
4172439#111827
5000#000000
="#"&DEC2HEX(A2,2)&DEC2HEX(B2,2)&DEC2HEX(C2,2) Explain

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.
Kyle Stott

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.