Bitwise NOT

All functions > BITWISE > Bitwise NOT

Returns the bitwise NOT (complement) of a bitstring, flipping every bit.

Syntax

~expr  ·  BITWISE_NOT(expr)

Notes

  • Every 0 becomes 1 and every 1 becomes 0
  • The length of the result is the same as the input
  • Returns NULL if the input is NULL

Related Functions

Examples

BITWISE_NOT(...)

FeatureQL
SELECT
    f1 := BITWISE_NOT('1010'::BITSTRING)::VARCHAR, -- Flip all bits
    f2 := BITWISE_NOT('0000'::BITSTRING)::VARCHAR, -- All zeros become all ones
    f3 := BITWISE_NOT('1111'::BITSTRING)::VARCHAR -- All ones become all zeros
;
Result
f1 VARCHARf2 VARCHARf3 VARCHAR
010111110000

Operator ~

FeatureQL
SELECT
    f1 := (~'1010'::BITSTRING)::VARCHAR, -- Flip all bits
    f2 := (~'0000'::BITSTRING)::VARCHAR, -- All zeros become all ones
    f3 := (~'1111'::BITSTRING)::VARCHAR -- All ones become all zeros
;
Result
f1 VARCHARf2 VARCHARf3 VARCHAR
010111110000

Last update at: 2026/05/26 17:22:09