Google Sheets HEX2BIN Function: How to Use It

How-to basics · Updated November 23, 2026

The Google Sheets HEX2BIN function converts a signed hexadecimal number into its signed binary (base-2) equivalent. Its syntax is HEX2BIN(signed_hexadecimal_number, [significant_digits]), where the first argument is the hex string you want to convert and the optional second argument controls how many binary digits are returned.

What HEX2BIN Does and Why It Matters

HEX2BIN is part of Google Sheets’ Engineering functions, a group that also includes BIN2HEX, DEC2BIN, and OCT2BIN. These functions are used when you need to work with number systems other than the decimal (base-10) system most people use daily. Computers and digital electronics rely on binary (base-2) and hexadecimal (base-16) representations, so engineers, programmers, and students often need to convert between them. Instead of doing the math by hand, HEX2BIN does it instantly for you.

For example, the hexadecimal number F equals the decimal number 15, which in binary is 1111. So =HEX2BIN("F") returns 1111. The function handles both positive and negative values, but with a crucial limitation: it only works with hexadecimal numbers that are up to 10 characters long (including a leading sign if negative).

How the Function Handles Positive and Negative Numbers

Understanding how HEX2BIN treats signs is the key to using it correctly. In Google Sheets, a hexadecimal number is considered “signed” if it starts with a minus sign (e.g., -1) or if it has 10 digits and the first digit is 8 or higher (e.g., FFFFFFFFFFFFFFFF). For positive numbers, the function simply converts the hex digits to binary, ignoring any leading zeros unless you specify significant_digits.

For negative numbers, HEX2BIN returns a 10-character binary string using two’s complement notation. Two’s complement is the standard way computers represent negative numbers in binary. For instance, =HEX2BIN("-1") returns 1111111111 (ten ones), which is the two’s complement representation of -1 in a 10-bit system. If you try to convert a negative hex number that is too large in magnitude (i.e., less than -512 in decimal), you’ll get a #NUM! error because the result would require more than 10 bits.

Using the Optional significant_digits Argument

The second argument, significant_digits, lets you force the output to have a minimum number of binary digits. This is useful when you want consistent formatting, such as always showing 8 bits for a byte. For example, =HEX2BIN("A", 8) returns 00001010 instead of just 1010. The function adds leading zeros to reach the specified length.

However, there are two important rules:

  • If significant_digits is less than the number of digits actually needed, Google Sheets returns a #NUM! error. For instance, =HEX2BIN("FF", 4) errors because FF (decimal 255) needs 8 bits.
  • If the hex number is negative, significant_digits is ignored, and the function always returns the full 10-character two’s complement representation.

Step-by-Step: How to Enter HEX2BIN in a Cell

Using HEX2BIN is straightforward. Here’s the exact process:

  1. Click on the cell where you want the binary result to appear.
  2. Type =HEX2BIN( to start the function.
  3. Enter the hexadecimal number as a string in double quotes (e.g., "1F") or reference a cell that contains the hex text (e.g., A2).
  4. If you want a specific number of digits, add a comma and a number, then close the parenthesis. Otherwise just close it.
  5. Press Enter. The binary result appears in the cell.

Example: If cell A1 contains the text 2A, then =HEX2BIN(A1) returns 101010. If you use =HEX2BIN(A1, 8), it returns 00101010.

Common Errors and How to Fix Them

You’ll likely encounter a few errors when using HEX2BIN. Here are the most common ones and what they mean:

  • #NUM! error: This appears when the hex number is too large (more than 10 characters), when the result would require more than 10 bits, or when significant_digits is too small or negative. Double-check your input length and the required digit count.
  • #VALUE! error: This appears if the first argument is not a valid hexadecimal string. Hex digits are 0-9 and A-F (case-insensitive). Make sure you haven’t included a ‘0x’ prefix or other invalid characters.
  • #N/A error: This can appear if you reference a cell that contains a number formatted as a decimal, not as text. HEX2BIN expects a text string or a cell containing text. If your cell has the number 10 (decimal), it will be interpreted as hex “10” (which is 16 decimal), not as the decimal number 10. To avoid confusion, store hex values as text with a leading apostrophe or use the TEXT function.

HEX2BIN vs. Other Conversion Functions

Google Sheets offers a full suite of base-conversion functions, and knowing which to use saves time:

  • BIN2HEX – converts binary to hexadecimal (opposite direction).
  • DEC2BIN – converts decimal to binary, but only for numbers up to 511 (positive) or -512 (negative).
  • HEX2DEC – converts hexadecimal to decimal.
  • OCT2BIN – converts octal to binary.

If you need to convert a number that is too large for HEX2BIN (e.g., a 64-bit hex value), you’ll need to split it into smaller chunks or use a custom script, as the built-in function has a 10-character limit. Also note that Excel’s HEX2BIN works similarly but has the same 10-character limit, so the behavior is consistent across platforms.

Practical Use Cases and Examples

HEX2BIN is not just an academic tool; it has real-world applications:

  • Networking: Converting MAC addresses (which are hex) into binary for subnet calculations.
  • Programming: Debugging bitwise operations where you need to see the binary representation of a hex constant.
  • Education: Teaching students how binary and hex relate, especially in computer science courses.
  • Data analysis: When importing logs that contain hex-encoded flags, you can convert them to binary to inspect individual bits.

Example: Suppose you have a list of hex color codes in column A (e.g., “FF0000” for red). You can extract the red component with =HEX2BIN(LEFT(A2,2), 8) to see the binary value of the red byte. This is a handy trick for understanding color channels.

Frequently Asked Questions

Can HEX2BIN convert a cell that contains a decimal number?
No. The function expects a hexadecimal string. If your cell contains the number 10 (decimal), Google Sheets will treat it as the hex string “10” (which is 16 in decimal). To avoid this, store hex values as text (e.g., with an apostrophe before the number) or use the TEXT function to format it as a string.

Why does HEX2BIN return 10 digits for negative numbers?
Because negative numbers are represented in two’s complement, and Google Sheets uses a fixed 10-bit system for binary output. This matches the maximum size for positive numbers (which can also be up to 10 bits). It’s a limitation of the function, not a bug.

What is the largest hexadecimal number I can convert?
For positive numbers, the largest is 3FF (which is 1023 in decimal, requiring 10 bits). For negative numbers, the most negative is -200 (which is -512 in decimal). Anything beyond that returns a #NUM! error.

Does HEX2BIN work in Excel the same way?
Yes, Excel’s HEX2BIN function has the same syntax and the same 10-character limit. The main difference is that in Excel, you may need to enable the Analysis ToolPak in older versions, but in modern Excel (2016 and later) it’s built in. The Google Sheets version is always available.

Can I convert a hex number with a decimal point?
No. HEX2BIN only handles integers. If you have a fractional hex value, you’ll need to handle the integer and fractional parts separately, but the function cannot do it directly.

Final Thoughts on HEX2BIN

HEX2BIN is a simple but powerful function for anyone working with number systems. Once you understand its limitations—the 10-character limit, the two’s complement for negatives, and the need for text input—you can use it confidently. For most everyday conversions, it’s faster than manual calculation, and it integrates seamlessly with other Google Sheets functions. If you ever need to go beyond its limits, consider splitting the number or using Google Apps Script for custom conversion logic.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.