DEC2BIN Function (LibreOffice Calc)

Engineering Beginner LibreOffice Calc Introduced in LibreOffice 3.0
number-systems binary engineering encoding bitwise

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.

Compatibility

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
DEC2BIN is ideal for low‑level modeling, bitwise operations, and encoding workflows — especially when paired with BIN2DEC, BITAND, and BASE().

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.

Copyright 2026. All rights reserved.