Bitwise AND
All functions > BITWISE > Bitwise AND
Returns the bitwise AND of two bitstrings.
Syntax
left & right · BITWISE_AND(left, right)
Notes
- Both operands must have the same length
- Each bit position is ANDed independently: 1 AND 1 = 1, all other combinations = 0
- Returns NULL if either input is NULL
Related Functions
Examples
BITWISE_AND(...)
FeatureQL
SELECT
f1 := BITWISE_AND('10101'::BITSTRING, '10001'::BITSTRING)::VARCHAR, -- AND preserves common 1-bits
f2 := BITWISE_AND('1111'::BITSTRING, '1010'::BITSTRING)::VARCHAR, -- Masking with AND
f3 := BITWISE_AND('1100'::BITSTRING, '0011'::BITSTRING)::VARCHAR -- No common bits
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR |
|---|---|---|
| 10001 | 1010 | 0000 |
Operator &
FeatureQL
SELECT
f1 := ('10101'::BITSTRING & '10001'::BITSTRING)::VARCHAR, -- AND preserves common 1-bits
f2 := ('1111'::BITSTRING & '1010'::BITSTRING)::VARCHAR, -- Masking with AND
f3 := ('1100'::BITSTRING & '0011'::BITSTRING)::VARCHAR -- No common bits
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR |
|---|---|---|
| 10001 | 1010 | 0000 |