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
ParameterTypeRequiredDescription
leftBITSTRINGYesFirst bitstring operand
rightBITSTRINGYesSecond 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 VARCHARf2 VARCHARf3 VARCHAR
110000001010

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19