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 Assignment) operator evaluates the binary representation of its left operand, shifts it to the right by the number of bits specified by the right operand, fills the vacated leftmost bits with zeroes, and assigns the resulting 32-bit unsigned integer back to the left operand.

Syntax

x >>>= y
This is the compound assignment equivalent of:
x = x >>> y

Technical Behavior

  1. 32-bit Conversion: Before the shift operation, TypeScript (inheriting from JavaScript) implicitly converts the left operand into a 32-bit unsigned integer. The right operand is converted to a 32-bit integer.
  2. Zero-Fill: Unlike the sign-propagating right shift (>>), the unsigned right shift (>>>) does not preserve the sign bit. It strictly pushes 0s in from the left. Consequently, the result of this operation is always a non-negative 32-bit integer, even if the initial left operand was a negative number.
  3. Modulo 32 Masking: The right operand is masked to 5 bits (y & 0x1F). This means the shift amount is strictly evaluated as a value between 0 and 31. Shifting by 32 is equivalent to shifting by 0.
  4. BigInt Incompatibility: Unlike other bitwise operators (such as >>, <<, &, |), the unsigned right shift is strictly prohibited for bigint types. Because bigint values are arbitrary-precision and lack a fixed bit-width, there is no defined “left edge” to fill with zeroes. Attempting to use >>>= with a bigint will throw compiler error TS2779.

Code Visualization

Example 1: Positive Integer
let x: number = 10; 
// 32-bit binary: 00000000000000000000000000001010

x >>>= 2; 
// Shifts right by 2, fills left with two 0s.
// 32-bit binary: 00000000000000000000000000000010
// x evaluates to 2
Example 2: Negative Integer (Demonstrating Zero-Fill)
let y: number = -10; 
// 32-bit binary (Two's complement): 11111111111111111111111111110110

y >>>= 1; 
// Shifts right by 1, forces a 0 into the sign bit.
// 32-bit binary: 01111111111111111111111111111011
// y evaluates to 2147483643
Example 3: Modulo 32 Shift
let z: number = 5;
// 32-bit binary: 00000000000000000000000000000101

z >>>= 32; 
// 32 & 0x1F evaluates to 0. Shifts right by 0.
// z remains 5
Example 4: BigInt Exception
let b: bigint = 10n;

b >>>= 2n; 
// Error: TS2779: The '>>>' and '>>>=' operators cannot be applied to 'bigint'.
Master TypeScript with Deep Grasping Methodology!Learn More