Excel converts numbers between decimal, binary, hexadecimal, and octal with a family of X2Y functions — handy for color codes, bit flags, and anything from the programming world.
HEX2DEC, BIN2DEC, etc. The pattern is fromBase 2 toBase.
The example
The same value in three bases.
| A | B | C | |
|---|---|---|---|
| 1 | Decimal | Hex | Binary |
| 2 | 255 | FF | 11111111 |
| 3 | 10 | A | 1010 |
The formula
Decimal to hex and binary:
How it works
The naming is consistent: SOURCE2TARGET:
DEC2HEX,DEC2BIN,DEC2OCTconvert from decimal to hex / binary / octal.HEX2DEC,BIN2DEC,OCT2DECconvert back to decimal.- There are direct cross-converters too —
HEX2BIN,BIN2HEX, etc. - An optional 2nd argument pads the result to a fixed width:
DEC2BIN(10, 8)gives00001010.
Hex color codes: split a color like FF8800 with HEX2DEC(MID(…)) to read its R, G, B values (255, 136, 0) — useful when matching brand colors to RGB.
Try it: interactive demo
Enter a decimal number (0-255).
Variations
Back to decimal
Hex/binary to decimal:
Padded binary
Fixed 8-bit width:
Hex color to RGB
Red channel of a hex color:
Pitfalls & errors
Range limits. DEC2BIN only handles -512 to 511; larger numbers error. Use enough digits/the right function for big values.
Results are text. DEC2HEX returns text like “FF” — you can’t do math on it directly. Convert back with HEX2DEC first.
Negative numbers use two’s complement. DEC2BIN(-1) returns a 10-digit complement form, not “-1.” Expected, but surprising.
Practice workbook
Frequently asked questions
How do I convert decimal to binary or hex in Excel?
How do I pad a binary number to a fixed width?
How do I read RGB values from a hex color code?
Stop fighting formulas. Learn them in a day.
This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.
See the Formulas & Functions Class