Working with computer systems, microcontrollers, networking masks, or digital hardware requires converting numbers between binary (base-2), decimal (base-10), and hexadecimal (base-16) numbering systems. Google Sheets provides built-in engineering conversion formulas that eliminate manual bitwise calculations. By understanding the syntax and constraints of the BIN2DEC, DEC2BIN, and HEX2DEC functions, you can automate base number conversions across technical datasets.
How Base Number Representations Function in Google Sheets
In Google Sheets, binary numbers are represented using up to 10 bits in two’s complement notation (where the most significant bit acts as the sign bit). The valid range for binary inputs is 0000000000 to 0111111111 for positive integers (up to decimal 511), and 1000000000 to 1111111111 for negative integers (down to decimal -512). Hexadecimal numbers support up to 10 characters (40 bits). Values outside these boundaries will return a #NUM! error.
Syntax and Parameters
1. BIN2DEC Function
Converts a signed binary number into its equivalent decimal integer.
=BIN2DEC(signed_binary_number)
signed_binary_number(Required): A string or numeric value representing a binary number with at most 10 bits.
2. DEC2BIN Function
Converts a decimal integer into a signed binary string.
=DEC2BIN(decimal_number, [significant_digits])
decimal_number(Required): The decimal integer to convert (-512 to 511).significant_digits(Optional): The number of padded digits to display. If omitted, Google Sheets displays the minimum required digits.
3. HEX2DEC Function
Converts a signed hexadecimal string into its equivalent decimal integer.
=HEX2DEC(signed_hexadecimal_number)
signed_hexadecimal_number(Required): A string representing a hexadecimal number of at most 10 hexadecimal digits.
Step-by-Step Practical Examples
Step 1: Converting Binary to Decimal with BIN2DEC
- Open a new spreadsheet and enter
11010110into cellA2. - In cell
B2, enter:=BIN2DEC(A2) - Press Enter. Google Sheets calculates the binary value and outputs
214. - To test two’s complement negative representation, enter
1111111111in cellA3and apply=BIN2DEC(A3). The formula returns-1.
Step 2: Converting Decimal to Padded Binary with DEC2BIN
- Enter
42into cellA4. - In cell
B4, format the output to an 8-bit padded byte by entering:=DEC2BIN(A4, 8) - Press Enter. The formula outputs
00101010, padding leading zeros cleanly.
Step 3: Converting Hexadecimal to Decimal with HEX2DEC
- Enter
1A3Finto cellA5. - In cell
B5, calculate the decimal equivalent using:=HEX2DEC(A5) - Press Enter. Google Sheets evaluates the hexadecimal characters and returns
6719.
Engineering Number Conversion Functions Comparison
| Function | Source Base | Target Base | Input Range Limit | Output Format | Common Application |
|---|---|---|---|---|---|
BIN2DEC |
Binary (Base-2) | Decimal (Base-10) | 10-bit (-512 to 511) | Numeric integer | Parsing register flags and GPIO states |
DEC2BIN |
Decimal (Base-10) | Binary (Base-2) | -512 to 511 | Text string (padded) | Generating bitmasks and subnet masks |
HEX2DEC |
Hexadecimal (Base-16) | Decimal (Base-10) | 10-digit hex | Numeric integer | Decoding memory addresses and colour codes |
DEC2HEX |
Decimal (Base-10) | Hexadecimal (Base-16) | -549,755,813,888 to 549,755,813,887 | Text string | Exporting RGB channel values |
BIN2HEX |
Binary (Base-2) | Hexadecimal (Base-16) | 10-bit binary | Text string | Condensing raw byte dumps into hex format |
Troubleshooting Common Errors
- #NUM! Error: Occurs when the input number exceeds the 10-bit limit (greater than 511 or less than -512 for
DEC2BIN), or whensignificant_digitsis smaller than the required digits. - #VALUE! Error: Occurs when passing invalid non-binary characters (such as digits 2-9) into
BIN2DEC, or invalid non-hex characters intoHEX2DEC. - Leading Zero Truncation: If entering binary numbers directly into cells without quotes, Google Sheets interprets them as standard decimals. Always wrap binary numbers in quotes (e.g.
"001101") or format the cell as Plain Text.