Engineering function

HEX2BIN function

Converts a hexadecimal number to binary text, for example "F" to "1111". Only values from -512 to 511 fit in the 10-bit result.

Available in Excel 2007 and later (Excel 2003 needed the Analysis ToolPak add-in), Microsoft 365, Excel for the web, Excel for Mac

Excel 2007 and laterWorks in Google Sheets

Syntax

HEX2BIN(number, [places])
ArgumentWhat it means
numberRequiredThe hexadecimal number to convert, as text or a number. At most 10 characters (40 bits): -549,755,813,888 to 549,755,813,887. A 10-character value whose first digit is the highest one is read as negative (two's complement).
placesOptionalMinimum number of characters to return, padded with leading zeros. Ignored when the result is negative.

Returns: Text containing the binary digits.

How HEX2BIN works

HEX2BIN expands a hexadecimal value into its individual bits. Each hex digit becomes four binary digits, so it is the quickest way to see which flags in a hex status code are switched on.

The catch is the size of the result: binary output is limited to 10 bits, so the input must represent a number between -512 and 511. Positive inputs can be at most 1FF; negative inputs must be 10 hex digits from FFFFFFFE00 (-512) to FFFFFFFFFF (-1). Anything else returns #NUM! even though it is perfectly valid hex. For bigger values, combine HEX2DEC with BASE: =BASE(HEX2DEC(A2),2).

Examples

1Expand a hex digit into bits

B2fx=HEX2BIN(A2, 8)
AB
1Hex
2F00001111

Result: 00001111

F is 15, which is 1111 in binary; places = 8 pads it to a full byte: 00001111.

2Check flags in a status code

B2fx=HEX2BIN(A2, 8)
AB
1Status
2B710110111

Result: 10110111

B is 1011 and 7 is 0111, so status B7 has bits 7, 5, 4, 2, 1 and 0 set: 10110111.

3A value too large for 10 bits

B2fx=HEX2BIN(A2)
AB
1Hex
2200#NUM!

Result: #NUM!

Hex 200 is 512 in decimal, one more than the largest 10-bit positive number, so Excel returns #NUM!. =BASE(HEX2DEC(A2),2) returns 1000000000 instead.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 15 KB

Common errors and how to fix them

ErrorWhy it happensFix
#NUM!The value is outside -512 to 511, the input is not valid hex or longer than 10 characters, or places is too small.Use =BASE(HEX2DEC(A2),2) for larger values; check the input for prefixes like 0x.

Tips

  • Remember that places is ignored for negative results, which are always 10 characters.
  • To test one bit without converting, use =BITAND(HEX2DEC(A2), 16)>0.

Google Sheets

HEX2BIN also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

HEX2BIN in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
DanishHEX.TIL.BIN
DutchHEX.N.BIN
FinnishHEKSABIN
FrenchHEXBIN
GermanHEXINBIN
HungarianHEX.BIN
ItalianHEX.BINARIO
Norwegian (Bokmål)HEKSTILBIN
PolishSZESN.NA.DWÓJK
Portuguese (Brazil)HEXABIN
Portuguese (Portugal)HEXABIN
RussianШЕСТН.В.ДВ
SpanishHEX.A.BIN
SwedishHEX.TILL.BIN