BITAND Function (LibreOffice Calc)

Mathematical Beginner LibreOffice Calc Introduced in LibreOffice 4.0
math bitwise binary masking flags number-systems

The BITAND function performs a bitwise AND operation on two non‑negative integers. It is used in binary workflows, masking, flag extraction, and low‑level numeric processing.

Compatibility

What the BITAND Function Does

  • Performs bitwise AND on two integers
  • Returns a number where each bit is 1 only if both inputs have a 1 in that position
  • Useful for masking, flag checks, and binary logic

Syntax

BITAND(number1; number2)

Arguments

  • number1:
    First non‑negative integer.

  • number2:
    Second non‑negative integer.

Basic Examples

Simple bitwise AND

=BITAND(6; 3)
→ 2

Because:

  • 6 = 110₂
  • 3 = 011₂
  • AND = 010₂ = 2

Using cell references

=BITAND(A1; B1)

AND with a mask

=BITAND(13; 4)
→ 4

Advanced Examples

Extract a specific bit (bit mask)

=BITAND(A1; 2^bit_position)

Check if a flag is set

=BITAND(A1; FLAG) > 0

Combine with BITOR to build masks

=BITAND(A1; BITOR(4; 8))

Convert result to binary

=DEC2BIN(BITAND(A1; A2); 10)

Use with BASE for arbitrary‑width binary

=BASE(BITAND(A1; A2); 2; 16)

Mask lower 4 bits

=BITAND(A1; 15)

Clear a bit

=BITAND(A1; BITXOR(2^bit; -1))

Edge Cases and Behavior Details

BITAND returns a non‑negative integer

Accepts:

  • Integers ≥ 0
  • Up to 48‑bit values (implementation‑dependent)

Behavior details

  • Negative numbers are not allowed
  • Fractional numbers are truncated
  • BITAND operates on binary representations
  • If either argument is 0 → result is 0
  • If both arguments are equal → result is the same number

Invalid input → Err:502

BITAND of an error → error propagates

Common Errors and Fixes

Err:502 — Invalid argument

Cause:

  • Negative numbers
  • Non-integer values
  • Non-numeric input

Fix:

  • Wrap with INT()
  • Ensure values ≥ 0
  • Validate numeric input

Unexpected zero result

Cause:

  • No overlapping 1‑bits

Fix:

  • Inspect binary forms using DEC2BIN

Best Practices

  • Use BITAND for masking and flag extraction
  • Combine with BITOR and BITXOR for full bitwise logic
  • Use DEC2BIN or BASE for debugging binary states
  • Validate inputs to avoid Err:502
  • Use powers of 2 for clean bit masks
BITAND is the backbone of binary masking — perfect for flag systems, low‑level logic, and compact data encoding.

Related Patterns and Alternatives

  • Use BITOR for bitwise OR
  • Use BITXOR for bitwise XOR
  • Use BITLSHIFT and BITRSHIFT for bit shifting
  • Use DEC2BIN and BIN2DEC for binary conversions
  • Use BASE for arbitrary‑length binary workflows

By mastering BITAND and its companion functions, you can build powerful bitwise and binary‑processing workflows in LibreOffice Calc.

Copyright 2026. All rights reserved.