DEC2BIN & Other Base Conversion Functions (HEX, OCT, BIN)

Excel base conversion functions DEC2BIN DEC2HEX DEC2OCT BIN2DEC HEX2DEC and OCT2DEC for converting number systems
Convert numbers between decimal, binary, hexadecimal, and octal formats using Excel’s built-in base conversion functions. This tutorial covers DEC2BIN, DEC2HEX, DEC2OCT, BIN2DEC, BIN2HEX, BIN2OCT, HEX2DEC, HEX2BIN, HEX2OCT, OCT2DEC, OCT2BIN, and OCT2HEX, with practical examples and explanations of how each function works. You’ll learn how to handle common conversion requirements, understand number systems, and use Excel for technical and engineering calculations. Ideal for students, programmers, engineers, analysts, IT professionals, and advanced Excel users working with different numerical bases.

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.

How binary place values build a decimal number 012806413201618041201 32 + 8 + 2 = 42, so decimal 42 becomes binary 00101010 =DEC2BIN(42) -> "101010" =BIN2DEC("101010") -> 42

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 naming pattern (FROM 2 TO): From DECIMAL: DEC2BIN DEC2HEX DEC2OCT From BINARY: BIN2DEC BIN2HEX BIN2OCT From HEX: HEX2DEC HEX2BIN HEX2OCT From OCTAL: OCT2DEC OCT2BIN OCT2HEX The "2" is shorthand for "to". So HEX2BIN reads as "hexadecimal to binary". Every conversion you need has a matching function in this grid.

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.

Syntax: =DEC2BIN(number, [places]) number -> the value to convert (given in the source base). places -> optional. Pads the result to this many digits with leading zeros. Examples: =DEC2BIN(5) -> "101" =DEC2BIN(5, 8) -> "00000101" (padded to 8 digits)
Results are text, not numbers. These functions return text strings, so "101" is not the number one hundred and one. Keep that in mind before doing arithmetic. To calculate, convert back to decimal first.

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.

Decimal into binary: =DEC2BIN(42) Result: "101010". Check it: 32 + 8 + 2 = 42, matching the place values. You can also add padding for a tidy byte layout: =DEC2BIN(42, 8) -> "00101010"

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.

Binary into decimal: =BIN2DEC("101010") Result: 42. Unlike the binary string, this 42 is a real number. So you can now add, multiply, or compare it freely. Always convert to decimal before doing arithmetic.

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.

Decimal into hex: =DEC2HEX(255) Result: "FF". The value 255 is the largest single byte, neatly shown as FF. A web colour like pure red is: =DEC2HEX(255, 2) & DEC2HEX(0, 2) & DEC2HEX(0, 2) -> "FF0000"

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.

Straight between two bases: Hex to binary: =HEX2BIN("A") -> "1010" Binary to hex: =BIN2HEX("1111") -> "F" Octal to hex: =OCT2HEX("17") -> "F" Each function goes directly, with no manual decimal stop in between the two bases.

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.

Negatives use two-complement form: =DEC2BIN(-5) Result: "1111111011". This is the 10-bit two-complement of minus five. Converting back recovers the original: =BIN2DEC("1111111011") -> -5 The binary range is -512 to 511, the span of 10 bits.

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.

Decimal
Binary
Hex
Octal
10
1010
A
12
16
10000
10
20
255
11111111
FF
377

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.

A guarded DEC2BIN: =IF(OR(number < -512, number > 511), "Out of range for binary (-512 to 511)", DEC2BIN(number)) How it behaves: Out of range -> a clear warning message. In range -> the binary string. For larger numbers, use DEC2HEX, which allows a much wider range than the narrow 10-bit binary limit.

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.

Pad to a fixed width: Without padding, lengths vary: =DEC2BIN(3) -> "11" =DEC2BIN(12) -> "1100" With 8-bit padding, everything aligns: =DEC2BIN(3, 8) -> "00000011" =DEC2BIN(12, 8) -> "00001100" Aligned bytes are far easier to scan and compare, which matters greatly when reading hardware registers or flags.

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.