DEC2BIN Function (LibreOffice Calc)
The DEC2BIN function converts a decimal (base‑10) number into a binary (base‑2) string. It supports optional padding and handles negative values using two’s complement representation.
Verification status: Consult the documentation, examples and any stated test scope below. How formula examples are checked
Availability and version history
- Introduced: Documented by LibreOffice 26.8.1.1; original introduction not established.
- Availability: Supported in LibreOffice 26.8.1.1, verified against its function registry. This identifies a supported release, not a final working version.
- Scope: Desktop Calc, using the English function name. Availability in other spreadsheet applications is separate.
- Checked: 2026-10-14 — function reference; versioned support. Documentation/source check; not a new native test. Existing example-specific test claims below retain their stated scope.
What the DEC2BIN Function Does
- Converts decimal → binary
- Returns a text string representing the binary number
- Supports optional minimum length padding
- Handles negative numbers using two’s complement (10‑bit)
- Useful in engineering, bitwise modeling, and encoding workflows
Syntax
DEC2BIN(number; [places])
Arguments
-
number:
Decimal integer between –512 and 511. -
places (optional):
Minimum length of the returned binary string.
Pads with leading zeros if necessary.
Basic Examples
Convert decimal to binary
=DEC2BIN(10)
→ "1010"
Convert with padding
=DEC2BIN(10; 8)
→ "00001010"
Convert a negative number
=DEC2BIN(-5)
→ "1111101011" (10‑bit two’s complement)
Advanced Examples
Force 16‑bit style output (manual padding)
=REPT("0"; 16-LEN(DEC2BIN(A1))) & DEC2BIN(A1)
Convert a range of values
=ARRAYFORMULA(DEC2BIN(A1:A10))
Combine with BIN2DEC for round‑trip validation
=BIN2DEC(DEC2BIN(A1))
Extract the lowest 4 bits
=RIGHT(DEC2BIN(A1; 4); 4)
Use in bitwise logic
=BITAND(A1; 1) = 1
Convert decimal → binary → hex
=DEC2HEX(BIN2DEC(DEC2BIN(A1)))
Edge Cases and Behavior Details
DEC2BIN returns text, not a number
Valid input range
- Minimum: –512
- Maximum: 511
Negative numbers use 10‑bit two’s complement
Example:
–1 → "1111111111"
–512 → "1000000000"
Behavior details
- If places is too small → Err:502
- If places is omitted → no padding
- If number is out of range → Err:502
- Leading zeros are added only when places is specified
Common Errors and Fixes
Err:502 — Invalid argument
Cause:
- Number outside –512 to 511
- places < length of binary result
- Non‑integer input
Fix:
- Clamp input to valid range
- Increase places
- Wrap with INT() if needed
Unexpected output for negative numbers
Cause:
- Two’s complement representation
Fix:
- Use BIN2DEC to interpret correctly
- Document bit width assumptions
Best Practices
- Always specify places when consistent width is required
- Use DEC2BIN for engineering and bitwise workflows
- Use BASE() for arbitrary‑base conversions
- Document two’s complement behavior for negative values
- Normalize binary strings before comparison
Related Patterns and Alternatives
- BIN2DEC — binary → decimal
- DEC2HEX / DEC2OCT — other base conversions
- BASE — general base conversion
- BITAND / BITOR / BITXOR — bitwise logic
- TEXT functions — padding and formatting
By mastering DEC2BIN, you can build precise binary‑based engineering and encoding models in LibreOffice Calc.
Reproducible example (tested in LibreOffice Calc)
This standalone example was calculated in LibreOffice Calc 25.2.3.2 and matched the expected value. It is a practical cross-check of one usage, not proof that every example elsewhere on this page is correct.
=DEC2BIN(10)
Expected result: 1010.
Display decimal ten using binary digits.
If the result differs, check the referenced cells, argument separators and number formatting. For more information, consult the LibreOffice Calc official help.