Programmers read binary. Network engineers read hexadecimal. Digital designers switch between both, plus octal, all day long. If your data mixes these number systems, you need a fast, reliable way to translate between them. Excel has a whole toolkit for exactly this. The DEC2BIN function turns a decimal number into binary, and it sits inside a family that converts freely between decimal, binary, hexadecimal, and octal. You give it a number, and it returns the same value written in another base.
This guide covers the whole conversion family, not just one function. First, it explains how the number systems relate to each other. Then it walks through every conversion direction with real examples. A set of worked examples and a full troubleshooting section follow. By the end, you will move between bases in any spreadsheet without reaching for a separate calculator.
The Number Systems at a Glance
Four number systems matter in computing today. Decimal is base ten, the everyday system. Binary is base two, the language of circuits. Hexadecimal and octal are compact shorthands for binary. The infographic below shows how binary place values build a number.
Each binary digit stands for a power of two. Reading them adds up to the decimal value. Because long binary strings are hard to read, hexadecimal packs four bits into one compact digit. Consequently, engineers switch between these systems constantly. Octal, base eight, works the same way with three bits per digit.
The Full Conversion Family
Helpfully, Excel names each function after its direction. The pattern is FROM followed by 2 followed by TO. So DEC2BIN goes from decimal to binary. Once you see the pattern, every name makes sense. You can almost guess a function name before checking it.
The Syntax and the Places Argument
As you would expect, each function takes the number to convert. Most also accept an optional places argument. That second value pads the result with leading zeros. It is handy for lining up a fixed-width display neatly. The padding is purely cosmetic, but it aids reading.
Example 1: Decimal to Binary
First, start with the core conversion. You turn a decimal number into binary. DEC2BIN does it in one clean step. The result is a text string of ones and zeros. That string is ready to display or store.
Example 2: Binary Back to Decimal
Similarly, the reverse is just as simple to do. You turn binary text back into a decimal number. BIN2DEC handles it in one step. This is how you get a usable number for maths. It is the essential companion to DEC2BIN.
Example 3: Decimal to Hexadecimal
Next, hexadecimal is the base of choice for many coders. It uses digits 0 to 9 and letters A to F. DEC2HEX produces it directly. Colours in web design are a familiar use. Memory addresses are another everyday example.
Example 4: Cross-Base Conversions
Importantly, you do not always pass through decimal. The family converts directly between bases. HEX2BIN jumps straight from hex to binary. This saves an extra step every time. It also avoids rounding or transcription mistakes.
Example 5: Handle Negative Numbers
Notably, binary can represent negative values too. Excel uses two-complement notation for them. A negative decimal produces a full-width binary string. The leading digits flag the sign clearly. This is the same scheme processors use internally.
Example 6: Build a Conversion Reference
For example, a side-by-side table is genuinely useful. You list decimal values in one column. Then you convert each into the other bases. This makes an instant reference chart.
Each column uses the matching DEC2 function. The decimal input drives all three conversions. Change a value, and the whole row updates at once. Such a table is a quick teaching aid for base systems. It also doubles as a live lookup during coding.
Example 7: Guard the Valid Range
However, DEC2BIN only accepts a limited range. Values outside minus 512 to 511 will fail. A short guard catches them first. This keeps a shared tool from showing raw errors. A friendly message is far more helpful.
Example 8: Align Bytes with Padding
Fixed-width output keeps data tidy. The places argument pads with leading zeros. This lines up every value to the same length neatly. It is vital when reading bytes or registers. Ragged columns are hard to compare by eye.
Troubleshooting Base Conversions
All three problems below are the most common. Each has a clear cause and a quick fix.
You get a #NUM! error
This error usually means the input is out of range. DEC2BIN only handles decimals from minus 512 to 511, since it produces a 10-bit result. A larger number simply will not fit and returns an error. Check the value against the limit, and switch to DEC2HEX for bigger numbers. The places argument can also trigger this error if it is too small to hold the result, or if it is negative. Make sure any padding you request is large enough for the converted value, and the error clears.
Arithmetic on the result gives wrong answers
If maths on a converted value behaves oddly, remember the results are text, not numbers. A binary string like "101" is text, so adding it to another value can concatenate or error rather than calculate. To do arithmetic, first convert the value back to decimal with BIN2DEC, HEX2DEC, or OCT2DEC. Perform your calculation on that real number. Then convert the answer back to the display base if needed. Keeping a clear line between the text display form and the numeric decimal form avoids these surprises entirely.
Hex or binary text is rejected as invalid
If a conversion rejects your input, the text may contain an invalid character for that base. Binary accepts only 0 and 1, octal only 0 to 7, and hexadecimal 0 to 9 plus A to F. A stray digit, a space, or a lowercase issue can cause a #NUM! error. Also confirm the value sits within the base range, since each function has limits. Clean the input so it contains only valid characters for the source base, with no spaces, and the conversion will succeed. Rebuilding the string carefully usually resolves it.
Frequently Asked Questions
- What does the DEC2BIN function do?+Essentially, DEC2BIN converts a decimal number into its binary representation as a text string. You give it a whole number, and it returns the ones and zeros that represent that value in base two. For example, =DEC2BIN(42) returns "101010", because 32 plus 8 plus 2 equals 42. An optional second argument pads the result with leading zeros to a fixed width, so =DEC2BIN(42, 8) returns "00101010". It works for decimals from minus 512 to 511, using two-complement notation for negatives. It belongs to a whole family of functions that convert between decimal, binary, hexadecimal, and octal.
- How do I convert between hexadecimal and binary?+Specifically, you use the direct cross-conversion functions rather than passing through decimal. HEX2BIN converts hexadecimal straight to binary, so =HEX2BIN("A") returns "1010", and BIN2HEX goes the other way, so =BIN2HEX("1111") returns "F". Excel provides a function for every pair of bases, following the pattern of the source base, then a 2, then the target base. This means you never need a manual decimal stopover. The full set covers decimal, binary, hexadecimal, and octal in every direction. Because hexadecimal digits map neatly onto four binary bits each, this conversion is exact and very common in programming work.
- Why do my converted values not calculate correctly?+Because these functions return text strings rather than numbers, ordinary arithmetic does not behave as expected on the results. A binary value like "101" is stored as text, so trying to add it to another value may join the strings or produce an error instead of a sum. To perform calculations, first convert the value back to a real decimal number using BIN2DEC, HEX2DEC, or OCT2DEC. Do your maths on that numeric result, then convert back to the display base if required. Keeping the text display form separate from the numeric decimal form is the key to avoiding these calculation problems.
- How are negative numbers handled in binary?+Notably, Excel represents negative numbers using two-complement notation, which is the standard method in computing. When you convert a negative decimal, DEC2BIN returns a full ten-digit binary string, so =DEC2BIN(-5) returns "1111111011". The leading ones indicate that the value is negative. Converting that string back with BIN2DEC correctly recovers minus five. This is why the binary functions are limited to the range of minus 512 to 511, which is exactly what ten bits can represent in two-complement form. If you need to work with larger magnitudes, the hexadecimal functions support a considerably wider range of values.