Contact

DEC2BIN in Google Sheets: Pad Binary Fields and Avoid Decimal Coercion

Engineering Intermediate Google Sheets

Create binary representations in Google Sheets, keep the signed input range visible and decode before performing arithmetic on returned digits.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

Quick answer: DEC2BIN(decimal_number,[significant_digits]) converts a decimal value to signed binary notation. The optional second argument supplies leading-zero padding; Google documents a numeric interval from −512 through 511.

Availability and version history

  • Introduced: first introduction date is not established by the reviewed official history; no desktop release number is inferred.
  • Availability: documented in the rolling Google Sheets service; these examples use the web worksheet workflow.
  • Checked: October 14, 2026; official DEC2BIN reference. Documentation and independent models, with no native Sheets execution or wider client certification.

Syntax and string conversion

=DEC2BIN(decimal_number,[significant_digits])

The decimal input is described as a string, but a valid numeric value is automatically converted to the appropriate input representation. Google’s explicit example makes numeric 199 and text “199” both produce 11000111.

significant_digits is optional. When it exceeds the required width, leading zeros are added; when it is too small, Google documents #NUM!. The argument is ignored for negative inputs. The short reference does not separately establish fractional-number truncation, fractional width, zero width or every invalid-input error.

The examples use integer values and explicit positive widths. Negative representations are checked against the signed ten-bit two’s-complement format in Google’s BIN2DEC definition, rather than importing a width policy from another product.

Example 1: create an eight-position binary column

Enter 0, 6, 21, 32 and 255 in A2:A6. In B2 enter and fill through B6:

=DEC2BIN(A2,8)
Decimal input Expected representation
0 00000000
6 00000110
21 00010101
32 00100000
255 11111111

For 21, the selected bit weights are 16+4+1. For 32, a single bit occupies the sixth position from the right. Padding aligns the output; it does not change the value or expand the function’s signed input interval.

In C2 use =BIN2DEC(B2) and fill down. The expected decoded numbers match column A. Keep the decimal source beside the display representation for ordinary arithmetic, sorting and validation.

A numeric input and its valid decimal text equivalent should follow the documented conversion rule. For example, =DEC2BIN(21,8) and =DEC2BIN("21",8) both have independently expected output 00010101.

Example 2: perform arithmetic in the correct base

Put =DEC2BIN(26,8) in E2. It produces 00011010, representing decimal 26. To add decimal 6 to its quantity, use:

=BIN2DEC(E2)+6

The result is 32. To display the sum in the same width:

=DEC2BIN(BIN2DEC(E2)+6,8)

The result is 00100000. This explicitly decodes, calculates and re-encodes.

Google warns that arithmetic on returned digit strings can silently treat them as decimal. With an unpadded 11010 in a cell, adding 6 as ordinary arithmetic gives 11016, which is not a binary representation of the intended sum. Padding alone is not a safe arithmetic conversion.

Advanced example: inspect negative values and endpoints

The documented signed interval is asymmetric because ten-bit two’s complement includes zero on its nonnegative side.

Decimal Expected signed representation
-512 1000000000
-3 1111111101
-1 1111111111
511 0111111111, with width 10

For −3, the independent representation calculation is 1024−3=1021, expressed in ten binary positions. Decoding subtracts 1024 again.

=DEC2BIN(-3,4) still follows the negative signed representation because the width argument is ignored. These examples use a valid positive width and do not claim how invalid optional arguments interact with negative values.

Decimal 512 lies outside the documented interval. Its unsigned binary spelling exists mathematically, but that does not make it an eligible DEC2BIN input. A different converter such as BASE has a separate contract and should be checked independently.

Advanced example: display a packed record

A six-bit record contains two three-bit fields. High=6 and low=5 give decimal 53. The formula =DEC2BIN(53,6) returns 110101.

=BITRSHIFT(53,3)
=BITAND(53,7)

These independently return 6 and 5. BITRSHIFT extracts the high portion; BITAND retains the low three positions. The display string helps inspect the format, while the bit functions perform numeric extraction.

Width errors and remaining limits

=DEC2BIN(21,4) requires five positions and follows the documented insufficient-width #NUM! rule. Width 5 gives 10101; width 8 gives 00010101. A larger width cannot repair an out-of-range decimal input.

Do not call the second argument a rounding precision: it controls representation width. Fractional inputs, invalid width values, extreme coercion and native error precedence remain unverified. The worked outputs are positional calculations and documented conversion expectations, not captured native results.

References and verification

Examples use fictional data, English function names and comma separators. Expected outputs are independent mathematical calculations or explicitly documented rules, not native Sheets captures. Check the spreadsheet locale when reproducing punctuation-sensitive formulas.