Please note javascript is required for full website functionality.

# A to Z of Excel Functions: The HEX2BIN Function

23 March 2020

Welcome back to our regular A to Z of Excel Functions blog. Today we look at the HEX2BIN function.

The HEX2BIN function This function converts a hexadecimal number (base 16) to binary (base two).

The HEX2BIN function employs the following syntax to operate:

HEX2BIN(number, [places])

The HEX2BIN function has the following arguments:

• number: this is required and represents the hexadecimal integer you wish to convert.  The number cannot contain more than 10 characters.  The most significant bit of number is the sign bit (40th bit from the right).  The remaining 39 bits are magnitude bits.  Negative numbers are represented using two's-complement notation
• places: this argument is optional.  This is the number of characters to use.  If places is omitted, HEX2BIN uses the minimum number of characters necessary.  The argument places is useful for padding the return value with leading 0s (zeros).

Two's complement is a mathematical operation on binary numbers, as well as a binary signed number representation based on this operation.  The two's complement of an N-bit number is defined as the complement with respect to 2N; in other words, it is the result of subtracting the number from 2N.  This is also equivalent to taking the ones' complement and then adding one, since the sum of a number and its ones' complement is all 1 bits.  The two's complement of a number behaves like the negative of the original number in most arithmetic, and positive and negative numbers can coexist in a natural way.

It should be further noted that:

• if number is negative, HEX2BIN ignores places and returns a 10-character binary number
• if number is negative, it cannot be less than FFFFFFFE00
• if number is positive, it cannot be greater than 1FF
• if number is not a valid hexadecimal number, HEX2BIN returns the #NUM! error value
• if HEX2BIN requires more than places characters, it returns the #NUM! error value
• if places is not an integer, it is truncated
• if places is nonnumeric, HEX2BIN returns the #VALUE! error value
• if places is negative, HEX2BIN returns the #NUM! error value. 