Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The >>> (unsigned right shift or zero-fill right shift) operator shifts the binary representation of the first operand to the right by the number of bits specified by the second operand. It discards bits shifted off the right and fills the newly vacated bits on the left with zeroes (0). Because it does not preserve the sign bit, the operation always evaluates to a non-negative 32-bit unsigned integer.
operand1 >>> operand2

Technical Mechanics

  1. Type Coercion: TypeScript (inheriting from JavaScript’s underlying ECMAScript specification) internally converts operand1 into a 32-bit unsigned integer (ToUint32).
  2. Shift Masking: operand2 is converted to an unsigned 32-bit integer and masked using a bitwise AND (operand2 & 0x1F). This restricts the actual shift amount to a value between 0 and 31 bits.
  3. Zero-filling: As bits are shifted to the right, the leftmost bits are populated with 0. This fundamentally alters negative numbers, as their leading 1 (the sign bit in two’s complement representation) is replaced by 0.
  4. Return Type: The result is always returned as a 32-bit unsigned integer, typed as number in TypeScript.
  5. BigInt Incompatibility: >>> is the only bitwise operator in TypeScript/JavaScript that does not support BigInt. Because BigInt represents arbitrary-precision integers without a fixed bit-width, an unsigned right shift is mathematically invalid. Attempting to use >>> with bigint operands throws a compilation error.

Behavior Visualization

Positive Integer Shift: When shifting positive numbers, >>> yields the exact same result as the sign-propagating right shift (>>) because the sign bit is already 0.
const a: number = 9; 
// 32-bit Binary: 00000000 00000000 00000000 00001001

const result1 = a >>> 2; 
// Shifted Right: 00000000 00000000 00000000 00000010
// result1 === 2
Negative Integer Shift: When shifting negative numbers, the 32-bit two’s complement representation is shifted. The leading 1s are replaced with 0s, resulting in a large positive integer.
const b: number = -9; 
// 32-bit Binary: 11111111 11111111 11111111 11110111

const result2 = b >>> 2; 
// Shifted Right: 00111111 11111111 11111111 11111101
// result2 === 1073741821
Float Truncation: If the left operand is a floating-point number, the fractional portion is truncated during the ToUint32 coercion before the shift occurs.
const c: number = 3.99; 
// Truncated to 3
// 32-bit Binary: 00000000 00000000 00000000 00000011

const result3 = c >>> 1; 
// Shifted Right: 00000000 00000000 00000000 00000001
// result3 === 1
Zero-Shift Coercion: Shifting by 0 bits forces any value into a 32-bit unsigned integer without altering its bit sequence.
const d: number = -1;
// 32-bit Binary: 11111111 11111111 11111111 11111111

const result4 = d >>> 0;
// Shifted Right: 11111111 11111111 11111111 11111111 (Interpreted as unsigned)
// result4 === 4294967295
BigInt Rejection: Applying >>> to bigint types results in a strict type error.
const e: bigint = 9n;

const result5 = e >>> 2n;
// TypeScript Error: Operator '>>>' cannot be applied to types 'bigint' and 'bigint'.
Master TypeScript with Deep Grasping Methodology!Learn More