TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
>> operator is the bitwise arithmetic right shift operator in Dart. It shifts the binary representation of the left operand to the right by the number of positions specified by the right operand. Because it is an arithmetic shift, it performs sign extension: the vacant bits on the left are filled with the value of the original sign bit (0 for positive numbers, 1 for negative numbers).
Mechanics
- Rightward Shift: Each bit in the binary representation of the
operandis moved to the right byshiftCountpositions. - Discarding Bits: The rightmost bits that are shifted past the least significant bit (LSB) are permanently discarded.
- Sign Extension: The leftmost bits (most significant bits, or MSB) vacated by the shift are populated with the original sign bit to maintain the integer’s mathematical sign.
Code Visualization
Positive Integer Shift When shifting a positive integer, the sign bit is0. Therefore, the vacated leftmost bits are filled with 0.
1. Therefore, the vacated leftmost bits are filled with 1.
Mathematical Equivalence
Evaluatinga >> b is mathematically equivalent to performing standard division (/) of a by 2 raised to the power of b, followed by a .floor() operation. Because .floor() truncates towards negative infinity, the >> operator yields different results for negative numbers compared to Dart’s integer division operator (~/), which truncates towards zero.
Platform-Specific Behavior
When using bitwise operators in Dart, the underlying architecture dictates the bit-width of the operands:- Native Platforms (AOT/JIT): Bitwise operations are evaluated using 64-bit signed integers.
- Web Platforms (JavaScript): Because Dart integers are mapped to JavaScript numbers on the web, operands are truncated to 32-bit signed integers before the bitwise shift is applied. This can result in different outputs across platforms when shifting large integers.
0 regardless of the sign bit), Dart provides the >>> (unsigned right shift) operator.
Master Dart with Deep Grasping Methodology!Learn More





