BIT_XOR
All functions > BITWISE > BIT_XOR
Returns the bitwise XOR (exclusive OR) of two bitstrings.
Signatures
Returns: Bitwise XOR of the two operands
BIT_XOR(left: BITSTRING, right: BITSTRING) → BITSTRING sql
| Parameter | Type | Required | Description |
|---|---|---|---|
left | BITSTRING | Yes | First bitstring operand |
right | BITSTRING | Yes | Second bitstring operand |
Notes
- Both operands must have the same length
- Each bit position is XORed independently: different bits = 1, same bits = 0
- XOR is its own inverse: A XOR B XOR B = A
- Returns NULL if either input is NULL
Examples
FeatureQL
SELECT
f1 := BIT_XOR('1010'::BITSTRING, '0110'::BITSTRING)::VARCHAR, -- Different bits become 1
f2 := BIT_XOR('1111'::BITSTRING, '1111'::BITSTRING)::VARCHAR, -- Same bits cancel out
f3 := BIT_XOR('1010'::BITSTRING, '0000'::BITSTRING)::VARCHAR -- XOR with zero preserves bits
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR |
|---|---|---|
| 1100 | 0000 | 1010 |
On this page