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])| Argument | What it means | |
|---|---|---|
number | Required | The 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). |
places | Optional | Minimum 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
| A | B | |
|---|---|---|
| 1 | Hex | |
| 2 | F | 00001111 |
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
| A | B | |
|---|---|---|
| 1 | Status | |
| 2 | B7 | 10110111 |
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
| A | B | |
|---|---|---|
| 1 | Hex | |
| 2 | 200 | #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.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#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
placesis 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.
| Language | Function name |
|---|---|
| Danish | HEX.TIL.BIN |
| Dutch | HEX.N.BIN |
| Finnish | HEKSABIN |
| French | HEXBIN |
| German | HEXINBIN |
| Hungarian | HEX.BIN |
| Italian | HEX.BINARIO |
| Norwegian (Bokmål) | HEKSTILBIN |
| Polish | SZESN.NA.DWÓJK |
| Portuguese (Brazil) | HEXABIN |
| Portuguese (Portugal) | HEXABIN |
| Russian | ШЕСТН.В.ДВ |
| Spanish | HEX.A.BIN |
| Swedish | HEX.TILL.BIN |