ThisCalculator

Everyday

Excel Number System Conversion: How to Use DEC2HEX

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

Excel Number System Conversion: How to Use DEC2HEX

Excel number system conversion means changing a number between decimal, binary, octal, and hexadecimal formats using built-in functions like DEC2BIN, DEC2OCT, DEC2HEX, and their reverse counterparts. You enter a decimal number and the target base, and Excel returns the equivalent value in that base as text. This article explains the functions, how to use them, common errors, and practical examples.

Formula

The core Excel functions are:

  • DEC2BIN(number, [places]) – converts a decimal integer to binary (base 2).
  • DEC2OCT(number, [places]) – converts to octal (base 8).
  • DEC2HEX(number, [places]) – converts to hexadecimal (base 16).
  • BIN2DEC, OCT2DEC, HEX2DEC – reverse the process, returning a decimal number.

All functions accept an optional places argument that pads the result with leading zeros to the specified width. The result is always returned as text, even if it looks like a number. The formula used in the calculator above is a simple conditional that picks the correct function based on the selected base.

Worked Example

Using the default values from the calculator: decimal 255, base 16.

  1. We need to convert 255 to hexadecimal.
  2. Excel formula: =DEC2HEX(255)
  3. Excel divides 255 by 16: 255 ÷ 16 = 15 remainder 15.
  4. In hexadecimal, 15 is represented as F, so the result is FF.
  5. The calculator returns FF, matching Excel’s output.

When to Use These Functions

Use DEC2BIN, DEC2OCT, and DEC2HEX when you need to:

  • Display memory addresses or color codes (hexadecimal).
  • Work with bitmasks or flags (binary).
  • Prepare data for systems that use octal (e.g., Unix file permissions, though those are usually handled differently).
  • Teach or learn number base concepts.

These functions are built into Excel and work in all modern versions, including Microsoft 365, Excel 2019, and Excel Online. They are part of the “Engineering” category.

How to Use in Excel

Enter the formula in a cell, for example:

=DEC2HEX(255)

This returns FF. To pad to 4 digits, use =DEC2HEX(255, 4) which gives 00FF. To convert back, use =HEX2DEC("FF") which returns 255.

For binary, =DEC2BIN(5) returns 101. For octal, =DEC2OCT(8) returns 10.

Common Errors and Limitations

  • #NUM! – The number is out of range. DEC2BIN accepts only -512 to 511 (10 bits). DEC2OCT accepts -536870912 to 536870911 (30 bits). DEC2HEX accepts -549755813888 to 549755813887 (40 bits). Negative numbers are represented in two’s complement.
  • #VALUE! – The number is not numeric, or the places argument is not an integer.
  • Text output – The result is text, so you cannot use it directly in arithmetic. Use VALUE() or double-unary (–) to convert if needed.
  • Places limit – If places is too small for the result, Excel returns #NUM!. If places is negative, also #NUM!.

These functions only work with integers. For fractions, you must handle the decimal part separately or use other methods.

Comparison with Manual Conversion

You can convert manually by repeatedly dividing by the base and reading remainders. For example, convert 255 to binary:

  1. 255 ÷ 2 = 127 remainder 1
  2. 127 ÷ 2 = 63 remainder 1
  3. 63 ÷ 2 = 31 remainder 1
  4. 31 ÷ 2 = 15 remainder 1
  5. 15 ÷ 2 = 7 remainder 1
  6. 7 ÷ 2 = 3 remainder 1
  7. 3 ÷ 2 = 1 remainder 1
  8. 1 ÷ 2 = 0 remainder 1

Reading remainders bottom-up gives 11111111. Excel’s function is faster and less error-prone, but manual conversion helps understand the process.

Alternatives and Related Functions

  • BASE(number, radix, [min_length]) – Converts any number to any base from 2 to 36, using digits 0-9 and letters A-Z. This is more flexible than DEC2HEX for bases beyond 16.
  • DECIMAL(text, radix) – Converts a text representation of a number in a given base back to decimal.
  • BITAND, BITOR, BITXOR – Perform bitwise operations, which often require binary conversion understanding.

For example, =BASE(255, 16) returns FF, same as DEC2HEX. To convert from base 36, =DECIMAL("ZZ", 36) returns 1295.

Frequently Asked Questions

Why does DEC2HEX return text instead of a number?

Because hexadecimal digits include letters A-F, Excel must return text to preserve the full representation. Even if the result is only digits (e.g., 255 to hex is FF, but 10 to hex is A), Excel always returns text. This avoids ambiguity and allows leading zeros when places is specified.

Can I convert a negative decimal number to binary?

Yes, DEC2BIN supports negative numbers, but it returns the two’s complement representation. For example, DEC2BIN(-1) returns 1111111111 (10 bits). The range is limited to -512 to 511, so large negatives will cause #NUM!.

How do I convert a number to base 3 or base 20?

Use the BASE function instead. =BASE(10, 3) returns 101, and =BASE(10, 20) returns A. DEC2BIN/OCT/HEX only support bases 2, 8, and 16 respectively.

What is the difference between DEC2HEX and BASE?

DEC2HEX is specialized for hexadecimal and supports negative numbers via two’s complement. BASE only works with positive integers and supports any base from 2 to 36. For most positive hex conversions, both give the same result, but BASE is more flexible.

Why do I get #NUM! when converting 1000 to binary?

Because 1000 exceeds the 10-bit limit of DEC2BIN (max 511). Use BASE(1000, 2) instead, which has no such limit for positive numbers, or split the number into parts.

Related

Formula used
in n | Decimal number | - | 255 | 0
in b | Target base (2, 8, or 16) | - | 16 | 2
out result | Converted value | - | if(b=2, DEC2BIN(n), if(b=8, DEC2OCT(n), DEC2HEX(n))) | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.