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 assignment operator in Dart. It performs a bitwise logical right shift on the left operand by the number of bit positions specified by the right operand, and then assigns the resulting value back to the left operand. Unlike the arithmetic right shift assignment (>>=), which performs sign extension by preserving the sign bit, the >>>= operator always shifts zeros into the most significant (leftmost) bits. This occurs regardless of whether the original integer’s two’s complement representation is positive or negative.

Syntax

a >>>= b;
This expression is functionally equivalent to the expanded assignment:
a = a >>> b;

Mechanics and Constraints

  1. Operand Types: Because >>>= is a compound assignment evaluated as a = a >>> b, the target variable a can be of any custom type that overloads operator >>>. The shift amount b can be of any type accepted by that specific overload. For built-in bitwise operations, both operands are typically of type int.
  2. Bit Discarding: The b least significant (rightmost) bits of a are shifted out of the binary sequence and discarded.
  3. Zero Padding: b number of 0 bits are inserted starting from the most significant (leftmost) bit downwards.
  4. Negative Shift Amounts: For built-in integers, the shift amount (b) must be non-negative. Passing a negative shift amount to a shift operator throws an ArgumentError (or a subclass such as RangeError, depending on the compiler) at runtime.
  5. Overshifting: The behavior of shifting by an amount greater than or equal to the integer’s bit-width depends entirely on the compilation platform.

Platform-Specific Execution

Because Dart compiles to both native machine code and JavaScript, the underlying bit-width of integers dictates the exact numerical output of this operator:
  • Native Platforms (VM, AOT): Integers are 64-bit. Applying >>>= to a negative number shifts b zeros in starting from the 64th bit downwards, resulting in a very large positive 64-bit integer. If the shift amount b is greater than or equal to 64, the result evaluates to 0.
  • Web Platforms (dart2js, DDC): Bitwise operations are truncated to 32-bit integers to comply with JavaScript’s bitwise mechanics. The b zeros are shifted in starting from the 32nd bit downwards. Additionally, the shift amount b is masked to 5 bits (evaluated as b % 32). Therefore, shifting by 32 is equivalent to shifting by 0, which does not universally result in 0 (e.g., -8 >>> 32 evaluates to 4294967288).

Code Visualization

void main() {
  int value = -8; 
  // 64-bit Native Binary: 11111111...11111000
  // 32-bit Web Binary:    11111111...11111000
  
  value >>>= 2; 
  
  // The operator shifts the bits right by 2 and forces 0s into the leftmost bits.
  // 64-bit Native Result: 00111111...11111110 (Value: 4611686018427387902)
  // 32-bit Web Result:    00111111...11111110 (Value: 1073741822)
  
  print(value); 
  
  // Overshifting behavior differences
  int overshiftNative = -8;
  overshiftNative >>>= 64; 
  // Evaluates to 0 on Native platforms (shift amount >= 64 bit-width)
  
  int overshiftWeb = -8;
  overshiftWeb >>>= 32;
  // Evaluates to 4294967288 on Web platforms (32 % 32 == 0, equivalent to -8 >>> 0)
}
Master Dart with Deep Grasping Methodology!Learn More