The Google Sheets BIN2HEX function converts a signed binary number (base 2) into its signed hexadecimal (base 16) equivalent. Its syntax is BIN2HEX(signed_binary_number, [significant_digits]), and it belongs to the Engineering function category.
What Is BIN2HEX and When Would You Use It?
BIN2HEX is one of several conversion functions in Google Sheets that translate numbers between different bases. You’d use it when you work with binary data—for example, when analyzing network masks, debugging microcontroller code, or converting color codes. Instead of doing the math by hand, the function does it instantly. It’s a pure calculation function: it takes a binary string, interprets it as a signed value, and returns the hexadecimal representation.
How the Function Works: Syntax and Arguments
The function requires one argument and optionally accepts a second:
signed_binary_number– The binary number you want to convert. It must be a string of 0s and 1s (e.g., “1010”). Google Sheets treats it as a signed 10-bit number, meaning the leftmost bit indicates the sign. The maximum input length is 10 bits (including the sign bit).significant_digits– (Optional) The minimum number of hexadecimal digits you want in the result. If you supply this, the result is padded with leading zeros to reach that length. If the result already has more digits, the padding is ignored. If you omit it, the function returns the minimum necessary digits.
For example, if cell A1 contains the binary string “1111111111” (which is -1 in signed 10-bit), then =BIN2HEX(A1) returns FFFFFFFFF (nine F’s, representing -1 in signed hex). If you add a second argument: =BIN2HEX(A1, 10), it returns FFFFFFFFFF (ten F’s, padded to 10 digits).
How to Use BIN2HEX in a Sheet: Step-by-Step
Using the function is straightforward:
- Click on a cell where you want the result.
- Type
=BIN2HEX(. - Enter a reference to a cell containing the binary number, or type the binary string in quotes, e.g.,
"1010". - Optionally, add a comma and a number for significant digits.
- Press Enter.
For instance, to convert binary 1010 (decimal 10) to hex, enter =BIN2HEX("1010") and it returns A. If you want at least 4 hex digits, use =BIN2HEX("1010", 4) and it returns 000A.
Common Errors and How to Avoid Them
You’ll likely encounter a few errors if the input isn’t valid:
#NUM!– This appears if the binary number has more than 10 bits, or if the significant_digits argument is negative or too large (Google Sheets allows up to 10 significant digits, but the exact limit depends on the result).#VALUE!– This appears if the binary string contains characters other than 0 or 1, or if significant_digits is not a number.#N/A– This appears if the function is not available (rare, but possible in older versions).
To avoid these, ensure your binary string is exactly 10 characters or fewer, and that it only contains 0s and 1s. Also, remember that the function interprets the number as signed—so “1111111111” is -1, not 1023. If you need unsigned conversion, you’d have to handle it differently (e.g., by adding a leading zero to force a positive interpretation, but that only works for numbers up to 511).
Comparing BIN2HEX with Other Conversion Functions
Google Sheets offers a family of base-conversion functions:
DEC2HEX– Converts decimal to hexadecimal.HEX2BIN– Converts hexadecimal to binary.BIN2DEC– Converts binary to decimal.OCT2HEX– Converts octal to hexadecimal.
All of these follow the same pattern: they accept a signed number in the source base and return a signed number in the target base. If you need to convert between bases that aren’t directly supported (like base-3), you’d have to build a custom formula using a combination of functions or a script.
Real-World Example: Converting Binary Data in a Sheet
Suppose you have a list of binary IP address masks in column A, and you want to see their hexadecimal equivalents. Put the binary strings in A2:A10, then in B2 enter =BIN2HEX(A2) and drag down. If the binary strings are longer than 10 bits, you’ll get a #NUM! error—so you’d need to split them into chunks first, which is beyond the function’s scope.
Another example: you’re working with color codes in binary (e.g., 8-bit red value as binary). If you have “11110000” in A1, =BIN2HEX(A1) returns F0, which is the hex equivalent of 240. This is handy when you need to convert binary data to a format that’s easier to read or use in other systems.
Frequently Asked Questions
Why does BIN2HEX return a negative number for inputs like “1111111111”?
Because the function treats the input as a signed binary number. In signed 10-bit representation, the leftmost bit is the sign bit. If it’s 1, the number is negative. So “1111111111” is -1 in two’s complement, and the hex result is FFFFFFFFF (nine F’s) which is the signed hex representation of -1. If you want a positive interpretation, you’d need to use a different method, like converting to decimal first and then to hex, but that only works for values within the positive range.
Can BIN2HEX convert binary numbers longer than 10 bits?
No. The function is limited to 10-bit signed numbers. If you try to use a longer string, you’ll get a #NUM! error. For longer binary numbers, you can split them into 10-bit chunks and convert each separately, but you’ll need to handle the sign and concatenation manually.
What does the significant_digits argument do exactly?
It sets a minimum length for the output string. If the converted hex number has fewer digits than significant_digits, the function pads it with leading zeros. If it has more, the padding is ignored. For example, =BIN2HEX("1010", 6) returns 00000A (padded to 6 digits). If you omit it, the result uses only the digits needed.
Is BIN2HEX available in Microsoft Excel?
Yes, Excel has the same function with the same syntax, but there are small differences: Excel’s BIN2HEX also handles 10-bit signed numbers, but the error messages and the exact behavior with significant_digits can vary slightly. In Excel, the function is under the Engineering category as well. If you’re working in Excel for the web, the function works the same as in Google Sheets.
Can I use BIN2HEX with cell references that contain text like “0b1010”?
No, the function expects a plain binary string—only 0s and 1s. If your cell contains a prefix like “0b”, you’ll need to strip it first, for example by using =BIN2HEX(SUBSTITUTE(A1,"0b","")).
Does BIN2HEX work with negative binary numbers written with a minus sign?
No, the function only accepts binary strings that represent the signed value using two’s complement. You cannot input “-1010” directly. Instead, you’d input the two’s complement representation, such as “1111110110” for -10. If you have a negative decimal number, you can use DEC2HEX to convert it directly.
Alternatives and Workarounds
If BIN2HEX doesn’t meet your needs, consider these alternatives:
- Use
BIN2DECto convert to decimal, thenDEC2HEXto convert that to hex. This works for positive numbers up to 511 (since 10-bit signed max is 511). - For larger binary numbers, split the string into chunks and convert each chunk, then concatenate the hex results. Be careful with sign handling—you may need to treat the leftmost chunk as signed.
- If you need to convert many values, consider writing a custom Google Apps Script function. That gives you full control over the conversion logic, but it’s overkill for most simple tasks.
Remember that BIN2HEX is a pure function—it doesn’t modify any data, so it’s safe to use in any sheet. There are no security concerns; it just returns a text result.
Related
- Balance Sheet Series 7: What It Is & How to Pass
- Fluid Balance Charting: What It Is and Why It Matters
- Battery Backup Calculation for UPS: How to Size Correctly
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How to Paste Into Filtered Cells in ExcelTo work with filtered cells in Excel, first decide whether you are copying different values to different visible…
- Add a Custom Number Format in Excel: Steps & ExamplesTo add a custom number format in Excel for Microsoft 365 on Windows, select the cells, press Ctrl+1,…
- Excel Row Stays When Scrolling? Keep It VisibleTo make an Excel row stay visible while you scroll, freeze it: in Excel for Microsoft 365 on…
- Excel Split Cell After a Character: Methods That WorkIn Excel for Microsoft 365 on Windows, split a cell at a character with Data > Text to…
- Autofill Numbers in Excel: Create a SeriesTo autofill numbers in Excel, enter the first two values of the pattern, select both cells, then drag…
- How to Enter a Page Break in Excel and Control PrintingTo enter a manual page break in Excel for Microsoft 365 on Windows, select the row below or…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.