BITXOR Function (LibreOffice Calc)
The BITXOR function performs a bitwise exclusive OR (XOR) operation on two non‑negative integers. It is used for toggling flags, detecting differences between bit patterns, and low‑level binary manipulation.
Compatibility
▾| Excel | ✔ |
| Gnumeric | ✔ |
| Google_sheets | ✔ |
| Libreoffice | ✔ |
| Numbers | ✖ |
| Onlyoffice | ✔ |
| Openoffice | ✖ |
| Wps | ✔ |
| Zoho | ✔ |
What the BITXOR Function Does ▾
- Performs bitwise XOR on two integers
- Sets each bit to 1 only if the inputs differ at that position
- Useful for toggling bits, detecting differences, and binary encoding
Syntax ▾
BITXOR(number1; number2)
Arguments
-
number1:
First non‑negative integer. -
number2:
Second non‑negative integer.
Basic Examples ▾
Simple bitwise XOR
=BITXOR(6; 3)
→ 5
Because:
- 6 = 110₂
- 3 = 011₂
- XOR = 101₂ = 5
Using cell references
=BITXOR(A1; B1)
Toggle a flag
=BITXOR(A1; FLAG)
Advanced Examples ▾
Detect which bits differ
=DEC2BIN(BITXOR(A1; A2); 10)
Toggle multiple flags at once
=BITXOR(A1; BITOR(4; 8))
XOR with a shifted mask
=BITXOR(A1; BITLSHIFT(1; 5))
Use with BASE for arbitrary‑width binary
=BASE(BITXOR(A1; A2); 2; 16)
Clear a bit using XOR with AND
=BITAND(A1; BITXOR(2^bit; -1))
Compute parity (odd/even number of 1‑bits)
=MOD(LEN(SUBSTITUTE(DEC2BIN(A1); "0"; "")); 2)
Edge Cases and Behavior Details ▾
BITXOR returns a non‑negative integer
Accepts:
- Integers ≥ 0
- Fractional inputs are truncated
Behavior details
- XOR outputs 1 only when bits differ
- XOR with 0 → returns the original number
- XOR with itself → returns 0
- Negative numbers are not allowed
- Very large values may overflow internal bit width
Invalid input → Err:502
BITXOR of an error → error propagates
Common Errors and Fixes ▾
Err:502 — Invalid argument
Cause:
- Negative numbers
- Non-integer inputs
- Non-numeric values
Fix:
- Wrap with INT()
- Ensure values ≥ 0
- Validate numeric input
Unexpected toggling
Cause:
- XOR flips bits rather than setting or clearing them
Fix:
- Use BITAND to clear bits
- Use BITOR to set bits
Best Practices ▾
- Use BITXOR to toggle flags or detect differences
- Use BITAND for masking and BITOR for combining flags
- Use DEC2BIN or BASE for debugging binary states
- Validate inputs to avoid Err:502
- Use XOR for parity checks and change detection
BITXOR is the perfect tool for toggling bits, detecting differences, and building compact binary‑encoded logic systems.
Related Patterns and Alternatives ▾
- Use BITAND for masking
- Use BITOR for combining flags
- Use BITLSHIFT and BITRSHIFT for shifting
- Use DEC2BIN and BIN2DEC for conversions
- Use BASE for arbitrary‑length binary workflows
By mastering BITXOR and its companion functions, you can build powerful bitwise and binary‑processing workflows in LibreOffice Calc.