BIN2HEX function
Converts a binary number to hexadecimal text, for example "11111011" to "FB". Optional padding with leading zeros.
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
BIN2HEX(number, [places])| Argument | What it means | |
|---|---|---|
number | Required | The binary number to convert, as text or a number. At most 10 characters (10 bits): -512 to 511. 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 hexadecimal digits.
How BIN2HEX works
BIN2HEX rewrites a binary number in hexadecimal. Because every hex digit stands for exactly four bits, this is a compact way to read a long bit pattern: 1111 1011 becomes FB. It is handy when a data sheet lists register values in binary but your software or documentation expects hex.
The input can be up to 10 binary digits. As with BIN2DEC, a 10-digit input that starts with 1 is a negative number in two's complement, and the hex result is then given as 10 characters (40-bit two's complement), for example FFFFFFFFFF for 1111111111. For positive results places pads the text with leading zeros; it is ignored for negative results.
Examples
1Convert a byte to hex
| A | B | |
|---|---|---|
| 1 | Binary | |
| 2 | 11111011 | 00FB |
Result: 00FB
11111011 is 251 in decimal, which is FB in hex. With places = 4 Excel pads it to 00FB.
2Short binary value
| A | B | |
|---|---|---|
| 1 | Binary | |
| 2 | 1110 | E |
Result: E
Four bits make one hex digit: 1110 = 8 + 4 + 2 = 14, written E.
3Negative binary value
| A | B | |
|---|---|---|
| 1 | Binary | |
| 2 | 1111111111 | FFFFFFFFFF |
Result: FFFFFFFFFF
Ten 1s is -1 in 10-bit two's complement, so the result is -1 in 40-bit hex: FFFFFFFFFF.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#NUM! | The input is longer than 10 characters, is not valid binary, or the result needs more characters than places. | Check the input for spaces or stray digits; raise places. |
#VALUE! | places is not a number. | Use a whole number for places. |
Tips
- Hex output is always upper case.
- For binary strings longer than 10 bits use
=BASE(DECIMAL(A2,2),16).
Google Sheets
BIN2HEX also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
BIN2HEX 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 | BIN.TIL.HEX |
| Dutch | BIN.N.HEX |
| Finnish | BINHEKSA |
| French | BINHEX |
| German | BININHEX |
| Hungarian | BIN.HEX |
| Italian | BINARIO.HEX |
| Norwegian (Bokmål) | BINTILHEKS |
| Polish | DWÓJK.NA.SZESN |
| Portuguese (Brazil) | BINAHEX |
| Portuguese (Portugal) | BINAHEX |
| Russian | ДВ.В.ШЕСТН |
| Spanish | BIN.A.HEX |
| Swedish | BIN.TILL.HEX |