Bitwise left shift
All functions > BITWISE > Bitwise left shift
Returns the bitstring shifted left by N positions, filling with zeros on the right.
Syntax
expr << n · BITWISE_SHIFT_LEFT(expr, n)
Notes
- Bits shifted beyond the left end are discarded
- New bits on the right are filled with zeros
- The length of the result is the same as the input
- Returns NULL if either input is NULL
Related Functions
Examples
BITWISE_SHIFT_LEFT(...)
FeatureQL
SELECT
f1 := BITWISE_SHIFT_LEFT('1001011'::BITSTRING, 3)::VARCHAR, -- Shift left by 3
f2 := BITWISE_SHIFT_LEFT('0001'::BITSTRING, 2)::VARCHAR, -- Shift left by 2
f3 := BITWISE_SHIFT_LEFT('1000'::BITSTRING, 1)::VARCHAR -- High bit shifted out
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR |
|---|---|---|
| 1011000 | 0100 | 0000 |
Operator <<
FeatureQL
SELECT
f1 := ('1001011'::BITSTRING << 3)::VARCHAR, -- Shift left by 3
f2 := ('0001'::BITSTRING << 2)::VARCHAR, -- Shift left by 2
f3 := ('1000'::BITSTRING << 1)::VARCHAR -- High bit shifted out
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR |
|---|---|---|
| 1011000 | 0100 | 0000 |