Categories: Bitwise
RSHIFT
Shifts the bits of the input value to the right by the specified number of positions, preserving the sign bit (arithmetic shift). Alias for SHIFTRIGHT. The shift amount is masked to the low-order 5 bits for INT (mod 32) and 6 bits for BIGINT (mod 64).
Syntax
RSHIFT(expression1 int32, expression2 int32) → int32
- expression1: Integer to shift.
- expression2: The number of bits to shift by.
Examples
RSHIFT exampleSELECT RSHIFT(1,1)
-- 0
SELECT RSHIFT(16, 1)
-- 8
SELECT RSHIFT(-1, 1)
-- -1
SELECT RSHIFT(1, NULL)
-- null
RSHIFT(expression1 int64, expression2 int64) → int64
- expression1: Integer to shift.
- expression2: The number of bits to shift by.
Examples
RSHIFT exampleSELECT RSHIFT(CAST(16 AS BIGINT), CAST(2 AS BIGINT))
-- 4