How do I do zero-fill right shift in Google Dart?
Something like: foo >>> 2 for instance.
Zero-fill right shift requires a specific integer size. Since integers in Dart are of arbitrary precision the '>>>' operator doesn't make sense there.
The easiest way to emulate a zero-fill right shift is to bit-and the number first.
Example:
(foo & 0xFFFF) >> 2 // 16 bit zero-fill shift
(foo & 0xFFFFFFFF) >> 2 // 32 bit shift.
You could define a utility function to use:
int zeroFillRightShift(int n, int amount) {
return (n & 0xffffffff) >> amount;
}
That assumes you have 32-bit unsigned integers and that's ok if you do have.
来源:https://stackoverflow.com/questions/11746504/how-to-do-zero-fill-right-shift-in-dart