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 >>> operator is the unsigned right shift (or logical right shift) operator in Dart. It shifts the binary representation of the left operand to the right by the number of bits specified by the right operand, filling the newly vacated most significant bits (leftmost bits) with zeros. This behavior contrasts with the arithmetic right shift operator (>>), which performs sign extension by filling the vacated bits with a copy of the original sign bit (1 for negative numbers, 0 for positive numbers).
int result = value >>> shiftAmount;

Bitwise Mechanics

Dart integers are represented using two’s complement. When the >>> operator is evaluated:
  1. The bits of value are shifted right by shiftAmount positions.
  2. The bits shifted off the right end (least significant bits) are discarded.
  3. The vacated bits on the left end (most significant bits) are populated strictly with 0.
Shift Amount Constraint: The shiftAmount (right operand) must be a non-negative integer. Passing a negative shift amount to any bitwise shift operator in Dart throws a RangeError.

Platform-Specific Behavior

Because Dart targets multiple platforms, the underlying bit-width of the integer dictates where the zero-fill occurs, how large shift amounts are handled, and the resulting sign:
  • Native (Dart VM / AOT):
    • Integers are 64-bit. The >>> operator shifts zeros into the 64th bit.
    • Shifting by an amount >= 64 pushes all bits out of the 64-bit boundary, resulting in 0.
  • Web (Compiled to JavaScript):
    • Bitwise operations in JavaScript treat operands as 32-bit integers. When running Dart on the web, >>> truncates the operand to 32 bits before shifting, and the zero-fill occurs at the 32nd bit.
    • Crucially, >>> on the web acts as a signed-to-unsigned 32-bit conversion. It always results in a positive number (or 0), regardless of the shift amount.
    • The shiftAmount is masked to 5 bits (evaluated as shiftAmount % 32). Consequently, shifting by 32 or greater wraps around. For example, x >>> 32 evaluates identically to x >>> 0.

Code Examples

Positive Integer Shift For positive integers, >>> yields the exact same result as >> because the sign bit is already 0.
int a = 16; 
// Binary: 00000000...00010000

int b = a >>> 2; 
// Binary: 00000000...00000100
// Result: 4 (Identical on Native and Web)
Negative Integer Shift For negative integers, shifting forces the sign bit to 0, fundamentally altering the numerical magnitude and resulting in a positive number. The exact result depends on the platform’s bit-width.
int x = -16; 

// Native (64-bit):
int yNative = x >>> 2; 
// 64-bit Binary: 0011111111111111111111111111111111111111111111111111111111111100
// Result: 4611686018427387900

// Web (32-bit):
int yWeb = x >>> 2;
// 32-bit Binary: 00111111111111111111111111111100
// Result: 1073741820
Zero Shift (>>> 0) The behavior of shifting by 0 diverges significantly between platforms due to the web’s unsigned 32-bit conversion semantics.
int z = -16;

// Native: No bits are vacated. The 64-bit value and sign remain completely unchanged.
int zNative = z >>> 0;
// Result: -16

// Web: Acts as a signed-to-unsigned 32-bit conversion, forcing a positive integer.
int zWeb = z >>> 0;
// Result: 4294967280
Master Dart with Deep Grasping Methodology!Learn More