The Excel HEX2BIN Function

Related Function:
Bin2Hex Function

Basic Description

The Excel Hex2Bin function converts a Hexadecimal (Base 16) number into a Binary (Base 2) number.

The syntax of the function is:

HEX2BIN( number, [places] )

Where the function arguments are:

number-The hexadecimal number that is to be converted to binary.
[places]-

An optional argument, which specifies the number of characters that you want the returned binary number to have.

If this is greater than the minimum, the binary number will be padded out using leading zeros.

If omitted, the returned binary uses the minimum number of places.

Note that the supplied number argument must not be more than 10 characters (40 bits) long. The most significant bit of this value denotes the sign of the number and the remaining 39 bits denote the magnitude. Negative numbers are represented using two's complement notation.

It should also be noted that, as hexadecimals use the numbers 0-9 and the characters a-f, they should be enclosed in quotation marks when they are supplied to an Excel function. (e.g. The hexadecimal 11a should be input as "11a").

  +   Display Hexadecimal and Binary Summary:

Hexadecimal

The Hexadecimal (Base 16) Numeral System uses the digits 0-9 and the characters a-f.

The following table shows the first 32 hexadecimal values, along with the equivalent decimal values:

Hexadecimal123456789abcdef101112131415161718191a1b1c1d1e1f20
Decimal1234567891011121314151617181920212223242526272829303132

For further information on the hexadecimal numeral system, see the Wikipedia Hexadecimal Page


Binary

The Binary (Base 2) Numeral System uses the digits 0 & 1.

The following table shows the first 8 binary values, along with the equivalent decimal values:

Binary110111001011101111000
Decimal12345678

For further information on the binary numeral system, see the Wikipedia Binary Page

Hex2Bin Function Examples

The following spreadsheets show five examples of the Excel Hex2Bin function.

 Formulas:
 A
1=HEX2BIN( "2" )
2=HEX2BIN( "0000000001" )
3=HEX2BIN( "2", 10 )
4=HEX2BIN( "F0" )
5=HEX2BIN( "1D" )
 Results:
 A
110
21
30000000010
411110000
511101

Note that, in the above example spreadsheet, the negative hexadecimal and binary numbers in cell A4 are represented by two's complement notation.


Further details and examples of the Excel Hex2Bin function are provided on the Microsoft Office website.


Hex2Bin Function Errors

If you get an error from the Excel Hex2Bin function this is likely to be one of the following:

Common Errors
#NUM!-

Occurs if either:

  • The supplied number argument is not recognised as a hexadecimal number or contains more than 10 characters;
  • The resulting binary number requires more places than is specified by the supplied [places] argument;
  • The supplied [places] argument is < 0 or > 10.
#VALUE!-Occurs if the supplied [places] argument is non-numeric.