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
-- Flip all bits
f1 := BITWISE_NOT('1010'::BITSTRING)::VARCHAR,
-- All zeros become all ones
f2 := BITWISE_NOT('0000'::BITSTRING)::VARCHAR,
-- All ones become all zeros
f3 := BITWISE_NOT('1111'::BITSTRING)::VARCHAR
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR |
|---|---|---|
| 0101 | 1111 | 0000 |
Operator ~
FeatureQL
SELECT
-- Flip all bits
f1 := (~ '1010'::BITSTRING)::VARCHAR,
-- All zeros become all ones
f2 := (~ '0000'::BITSTRING)::VARCHAR,
-- All ones become all zeros
f3 := (~ '1111'::BITSTRING)::VARCHAR
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR |
|---|---|---|
| 0101 | 1111 | 0000 |