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 bitwise right shift assignment operator in Dart. It performs an arithmetic (sign-propagating) right shift on the binary representation of the left operand by the number of bits specified by the right operand, and subsequently assigns the computed value back to the left operand.
variable >>= shiftAmount;
This operation is syntactically equivalent to the expanded assignment:
variable = variable >> shiftAmount;

Technical Mechanics

  • Operand Constraints: Both the left operand (the value being mutated) and the right operand (the shift magnitude) must be of type int.
  • Sign Propagation: Dart integers utilize two’s complement binary representation. The >>= operator performs an arithmetic shift, meaning it preserves the most significant bit (the sign bit) during the shift.
    • If the left operand is positive (sign bit 0), empty spaces on the left are filled with 0s.
    • If the left operand is negative (sign bit 1), empty spaces on the left are filled with 1s.
  • Truncation: The least significant bits that are shifted past the 0th position on the right are permanently discarded.

Syntax Visualization

void main() {
  // Positive integer shift
  int a = 24;      // Binary: 0001 1000
  a >>= 2;         // Shift right by 2 bits. Left-fills with 0s.
  print(a);        // Output: 6 (Binary: 0000 0110)

  // Negative integer shift (Sign bit preserved)
  int b = -24;     // Binary: 1110 1000 (Two's complement representation)
  b >>= 2;         // Shift right by 2 bits. Left-fills with 1s.
  print(b);        // Output: -6 (Binary: 1111 1010)
}
(Note: If zero-fill/logical right shift assignment is required regardless of the sign bit, Dart provides the >>>= operator instead).
Master Dart with Deep Grasping Methodology!Learn More