>>> operator is the unsigned right shift (also known as logical right shift) operator. It shifts the bits of the left operand to the right by the number of positions specified by the right operand, filling the vacated most significant bits (MSBs) with zeros regardless of the sign of the original number.
Syntax
Operational Mechanics
The>>> operator performs a bitwise manipulation on the binary representation of an integer.
- Bit Shifting: The bits of the
operandare moved to the right byshiftAmount. - Truncation: The least significant bits (LSBs) shifted past the zero index are discarded.
- Zero-Filling: The new bits introduced at the most significant end (the left side) are always set to
0.
Distinction from Arithmetic Shift (>>)
The primary distinction between the standard right shift (>>) and the unsigned right shift (>>>) lies in how they handle the most significant bit (the sign bit) for negative numbers:
- Arithmetic Shift (
>>): Performs sign extension. If the number is negative (MSB is 1), it fills vacated bits with 1s to preserve the sign. - Unsigned Shift (
>>>): Performs zero-filling. It always fills vacated bits with 0s. Consequently, shifting a negative number via>>>results in a positive integer.
Examples
The following examples assume a standard 64-bit integer environment (Dart VM).Positive Integers
For positive numbers,>>> behaves identically to >> because the MSB is already 0.
Negative Integers
For negative numbers,>>> alters the sign bit, resulting in a large positive integer.
Platform Specifics
- Dart Native (VM): Operations are performed on 64-bit integers.
- Dart Web: Bitwise operations are mapped to JavaScript 32-bit integers. Therefore,
>>>on the web will truncate the operand to 32 bits before shifting, resulting in a 32-bit unsigned integer range.
Master Dart with Deep Grasping Methodology!Learn More





