Engineering function

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])
ArgumentWhat it means
numberRequiredThe 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).
placesOptionalMinimum 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

B2fx=BIN2HEX(A2, 4)
AB
1Binary
21111101100FB

Result: 00FB

11111011 is 251 in decimal, which is FB in hex. With places = 4 Excel pads it to 00FB.

2Short binary value

B2fx=BIN2HEX(A2)
AB
1Binary
21110E

Result: E

Four bits make one hex digit: 1110 = 8 + 4 + 2 = 14, written E.

3Negative binary value

B2fx=BIN2HEX(A2)
AB
1Binary
21111111111FFFFFFFFFF

Result: FFFFFFFFFF

Ten 1s is -1 in 10-bit two's complement, so the result is -1 in 40-bit hex: FFFFFFFFFF.

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

Common errors and how to fix them

ErrorWhy it happensFix
#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.

LanguageFunction name
DanishBIN.TIL.HEX
DutchBIN.N.HEX
FinnishBINHEKSA
FrenchBINHEX
GermanBININHEX
HungarianBIN.HEX
ItalianBINARIO.HEX
Norwegian (Bokmål)BINTILHEKS
PolishDWÓJK.NA.SZESN
Portuguese (Brazil)BINAHEX
Portuguese (Portugal)BINAHEX
RussianДВ.В.ШЕСТН
SpanishBIN.A.HEX
SwedishBIN.TILL.HEX