Skip to main content

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 example
SELECT RSHIFT(1,1)
-- 0
Shift right by one position
SELECT RSHIFT(16, 1)
-- 8
Shift right and preserve the sign bit
SELECT RSHIFT(-1, 1)
-- -1
Shift right with a NULL argument
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 example
SELECT RSHIFT(CAST(16 AS BIGINT), CAST(2 AS BIGINT))
-- 4