Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Signed right shift operator (>>)

The >> operator shifts bits right while preserving the sign. For Number it operates on signed 32-bit integers; for BigInt it does not restrict values to 32 bits. The shift-count rules differ between these types.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

value >> shiftCount

value >> shiftCount performs an arithmetic right shift: it discards bits on the right and copies the sign bit into the leftmost positions. It does not modify its operands. After conversion to numeric values, both operands must have the same type: Number or BigInt. Mixing types, as in 8n >> 1, throws TypeError.

For Number, the left operand undergoes ToInt32 and the right operand undergoes ToUint32; the shift count is then reduced modulo 32. Thus, 20 >> 34 means the same as 20 >> 2. Conversion discards fractional parts and wraps values into the 32-bit range: even 4294967295 >> 0 produces -1. Do not use this operator as a general replacement for division or rounding.

After conversion of the left operand, shifting by k bits corresponds to division by 2 ** k, rounded down: -9 >> 1 produces -5, not -4. Unlike >>, the >>> operator fills vacated positions with zeros and returns an unsigned result for Number.

For BigInt, there is no reduction to 32 bits and no modulo-32 shift count. A nonnegative shift count means division by the corresponding power of two, rounded down; a negative count reverses the direction, so 3n >> -2n produces 12n. The >>> operator does not support BigInt.

Examples

console.log(20 >> 2);
console.log(-9 >> 1);
console.log(20 >> 34);
console.log(4294967295 >> 0);
console.log(String(-9n >> 1n));
console.log(String(3n >> -2n));

Result

5
-5
5
-1
-5
12

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources