
Decimal Base Conversions (DEC2HEX & DEC2BIN)
Learn how to convert decimal numbers to hex, binary, and octal in Excel using DEC2HEX, DEC2BIN, and DEC2OCT. Learn places padding and sign bit limits cleanly.
Front-end web developers and design system architects manage color palettes represented as Base-10 integer RGB values (such as Red 255, Green 128, Blue 15). To generate CSS color codes, these numbers must be transformed into two-digit hexadecimal strings ("FF", "80", "0F").
Converting a single-digit hex value (like 15 producing "F") without a leading zero breaks web color formatting. Excel provides base conversion formulas that feature an optional [places] argument to control zero padding: DEC2HEX, DEC2BIN, and DEC2OCT.
Quick Comparison: Decimal Conversion Formulas
| Formula | Converts From | Converts To | Input Range | Common Application |
|---|---|---|---|---|
DEC2HEX(num, [places]) |
Base-10 (Decimal) | Base-16 (Hex) | -549,755,813,888 to +549,755,813,887 | RGB color codes, MAC addresses, and memory offsets. |
DEC2BIN(num, [places]) |
Base-10 (Decimal) | Base-2 (Binary) | -512 to +511 | Hardware register bit masks and logic circuit simulation. |
DEC2OCT(num, [places]) |
Base-10 (Decimal) | Base-8 (Octal) | -536,870,912 to +536,870,911 | Linux file system permissions (e.g. chmod 755). |
Deep Technical Mechanics
1. Padding Zeros with [places]
The optional places argument specifies the exact number of characters to return, padding the left with zeros:
=DEC2HEX(15)returns"F"(1 character).=DEC2HEX(15, 2)returns"0F"(2 characters, ready for CSS).=DEC2BIN(5, 8)returns"00000101"(full 8-bit byte).
2. The Capacity Error (#NUM!)
If the converted result requires more characters than you specified in places, Excel throws a #NUM! error. For example, =DEC2HEX(255, 1) fails because 255 requires at least 2 hex digits ("FF").
Hands-on Practice Playground
Use the RGB color channel table below to convert decimal values into padded hexadecimal and binary notation. Follow each objective to complete the exercise.
In cell C2, convert the decimal value in B2 into a 2-digit hex code using DEC2HEX.
In cell C2, convert decimal value B2 into a 2-digit hexadecimal string padded with leading zeros by setting places to 2 in the DEC2HEX formula.
In cell D2, convert the decimal value into an 8-bit padded binary string.
In cell D2, convert decimal value B2 into an 8-bit binary string padded with leading zeros using the DEC2BIN formula with places set to 8.
In cell E2, convert the decimal value into octal notation with 3 places.
In cell E2, convert decimal value B2 into octal base-8 notation using the DEC2OCT formula with places set to 3.
Share This Lesson
Spread the word with your peers and challenge your friends