Convert Between Binary, Hex & Decimal

Excel Formulas › Math

All versionsDEC2BINHEX2DEC

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.


Quick formula: to convert a decimal number to hex and binary:
=DEC2HEX(A2) // decimal → hex =DEC2BIN(A2) // decimal → binary
Reverse with HEX2DEC, BIN2DEC, etc. The pattern is fromBase 2 toBase.

Functions used (tap for the full reference guide):

The example

The same value in three bases.

ABC
1DecimalHexBinary
2255FF11111111
310A1010

The formula

Decimal to hex and binary:

=DEC2HEX(255) → FF =DEC2BIN(10) → 1010

How it works

The naming is consistent: SOURCE2TARGET:

  1. DEC2HEX, DEC2BIN, DEC2OCT convert from decimal to hex / binary / octal.
  2. HEX2DEC, BIN2DEC, OCT2DEC convert back to decimal.
  3. There are direct cross-converters too — HEX2BIN, BIN2HEX, etc.
  4. An optional 2nd argument pads the result to a fixed width: DEC2BIN(10, 8) gives 00001010.

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

Live demo

Enter a decimal number (0-255).

Hex:   Binary:

Variations

Back to decimal

Hex/binary to decimal:

=HEX2DEC("FF") → 255

Padded binary

Fixed 8-bit width:

=DEC2BIN(10, 8) → 00001010

Hex color to RGB

Red channel of a hex color:

=HEX2DEC(MID(A2, 1, 2))

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

📊
Download the free Convert Between Binary, Hex & Decimal practice workbook
Decimal/hex/binary conversions with results shown, the padded and hex-color variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I convert decimal to binary or hex in Excel?
Use =DEC2BIN(n) for binary, =DEC2HEX(n) for hex, =DEC2OCT(n) for octal. Reverse with BIN2DEC, HEX2DEC, OCT2DEC.
How do I pad a binary number to a fixed width?
Add a second argument for places: =DEC2BIN(10, 8) returns 00001010.
How do I read RGB values from a hex color code?
Split and convert each pair: =HEX2DEC(MID(color, 1, 2)) reads the red channel, MID(...,3,2) green, MID(...,5,2) blue.

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

Related formulas: Insert special characters (CHAR) · Remainders & cycles (MOD) · Roman numerals

Function references: DEC2BIN · DEC2HEX · HEX2DEC