ZetCode

Excel DEC2BIN and HEX2DEC Functions

last modified April 4, 2025

The DEC2BIN and HEX2DEC functions are essential for working with number systems in Excel. DEC2BIN converts decimal numbers to binary, while HEX2DEC converts hexadecimal to decimal. This tutorial provides a comprehensive guide to using these functions with detailed examples. You'll learn syntax, practical applications, and important limitations of these conversion functions.

Function Basics

DEC2BIN converts decimal numbers to binary representation, while HEX2DEC converts hexadecimal numbers to decimal. These functions are particularly useful in computer science and digital electronics.

Function Description Syntax
DEC2BIN Converts decimal to binary =DEC2BIN(number, [places])
HEX2DEC Converts hexadecimal to decimal =HEX2DEC(number)

This table shows the basic information about both functions. DEC2BIN has an optional places parameter to pad the result with leading zeros.

DEC2BIN Basic Example

This example demonstrates the simplest use of DEC2BIN to convert a decimal number to its binary representation.

Basic DEC2BIN formula
=DEC2BIN(10)

This formula converts the decimal number 10 to binary. The result will be "1010". The function automatically determines the minimum number of bits needed.

DEC2BIN with Places Parameter

The optional places parameter specifies the minimum number of characters in the result. This example shows how to pad the binary result with leading zeros.

DEC2BIN with places
=DEC2BIN(5, 8)

This formula converts decimal 5 to an 8-bit binary number. The result is "00000101". The places parameter ensures the output has exactly 8 characters.

HEX2DEC Basic Example

This example shows the basic usage of HEX2DEC to convert a hexadecimal number to decimal.

Basic HEX2DEC formula
=HEX2DEC("A")

This formula converts the hexadecimal value "A" (which equals 10 in decimal) to its decimal equivalent. The result will be 10. Both uppercase and lowercase hex digits work.

HEX2DEC with Multi-digit Hexadecimal

HEX2DEC can handle multi-digit hexadecimal numbers. This example converts a two-digit hex value to decimal.

HEX2DEC with two-digit hex
=HEX2DEC("FF")

This formula converts hexadecimal "FF" to decimal. The result is 255, which is the maximum value for an 8-bit unsigned integer. The function handles hex strings up to 10 characters.

DEC2BIN with Negative Numbers

DEC2BIN can represent negative numbers using two's complement notation. This example shows how negative decimal numbers are converted.

DEC2BIN with negative number
=DEC2BIN(-5)

This formula converts decimal -5 to its 10-bit two's complement binary representation. The result is "1111111011". The function always uses 10 bits for negative numbers.

HEX2DEC with Large Values

HEX2DEC can handle large hexadecimal values. This example converts a 10-character hex string to decimal.

HEX2DEC with large value
=HEX2DEC("FFFFFFFFFE")

This formula converts the 10-character hex value "FFFFFFFFFE" to decimal. The result is -2. Negative values are represented using two's complement notation when the leftmost bit is 1.

DEC2BIN Limitations

DEC2BIN has specific limitations regarding input range and output length. This example demonstrates these limits.

DEC2BIN with maximum input
=DEC2BIN(511)

This formula converts the maximum positive decimal number (511) that DEC2BIN can handle. The result is "111111111" (9 bits). For negative numbers, the limit is -512. Attempting larger values returns #NUM!.

Combining DEC2BIN and HEX2DEC

These functions can be combined to convert between different number systems. This example converts hexadecimal to binary via decimal.

Hex to binary conversion
=DEC2BIN(HEX2DEC("A5"))

This formula first converts hex "A5" to decimal (165), then converts that to binary. The result is "10100101". This technique is useful when direct hex to binary conversion isn't available.

Practical Application Example

These functions are often used in digital systems. This example shows how to convert an IP address component from decimal to binary.

IP address component conversion
=DEC2BIN(192, 8)

This formula converts the decimal IP address component 192 to 8-bit binary "11000000". The places parameter ensures proper 8-bit formatting for each octet in an IP address.

The DEC2BIN and HEX2DEC functions are powerful tools for number system conversions in Excel. While DEC2BIN handles decimal to binary conversion with optional padding, HEX2DEC converts hexadecimal to decimal. Understanding their limitations and combining them can solve complex conversion problems in digital systems and programming.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.

List all Excel Formulas.