Bitwise XOR
All functions > BITWISE > Bitwise XOR
Returns the bitwise XOR (exclusive OR) of two bitstrings or two integers.
Syntax
BITWISE_XOR(left, right)
Function form
Returns: Result bitstring, or NULL if either operand is NULL
BITWISE_XOR(left: BITSTRING, right: BITSTRING) → BITSTRING sql
| Parameter | Type | Required | Description |
|---|---|---|---|
left | BITSTRING | Yes | Left operand |
right | BITSTRING | Yes | Right operand |
Returns: Result integer, or NULL if either operand is NULL
BITWISE_XOR(left: BIGINT, right: BIGINT) → BIGINT sql
| Parameter | Type | Required | Description |
|---|---|---|---|
left | BIGINT | Yes | Left operand (any integer type, read as 64 bits) |
right | BIGINT | Yes | Right operand (any integer type, read as 64 bits) |
Notes
- Bitstring operands must have the same length; bitstrings exist on DuckDB and Postgres only
- Integers are 64-bit two's complement and the result is a BIGINT, on every backend
- Each bit position is XORed independently: different bits = 1, same bits = 0
- XOR is its own inverse: BITWISE_XOR(BITWISE_XOR(a, b), b) = a
- Returns NULL if either input is NULL
- The
^token is numeric exponentiation in FeatureQL, not bitwise XOR—useBITWISE_XOR
Examples
FeatureQL
RETURN
-- Different bits become 1
f1 := BITWISE_XOR('1010'::BITSTRING, '0110'::BITSTRING)::VARCHAR,
-- Same bits cancel out
f2 := BITWISE_XOR('1111'::BITSTRING, '1111'::BITSTRING)::VARCHAR,
-- XOR with zero preserves bits
f3 := BITWISE_XOR('1010'::BITSTRING, '0000'::BITSTRING)::VARCHAR
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR |
|---|---|---|
| 1100 | 0000 | 1010 |
BITWISE_XOR()
FeatureQL
RETURN
-- Different bits become 1
f1 := BITWISE_XOR('1010'::BITSTRING, '0110'::BITSTRING)::VARCHAR
;Result
| f1 VARCHAR |
|---|
| 1100 |
On this page