Bitwise and shift operators
You can manipulate the individual bits of numbers in Dart. Usually,you’d use these bitwise and shift operators with integers.
| Operator | Meaning |
|---|---|
& | AND |
| | OR |
^ | XOR |
~expr | Unary bitwise complement (0s become 1s; 1s become 0s) |
<< | Shift left |
>> | Shift right |
Here’s an example of using bitwise and shift operators:
final value = 0x22;final bitmask = 0x0f;assert((value & bitmask) == 0x02); // ANDassert((value & ~bitmask) == 0x20); // AND NOTassert((value | bitmask) == 0x2f); // ORassert((value ^ bitmask) == 0x2d); // XORassert((value << 4) == 0x220); // Shift leftassert((value >> 4) == 0x02); // Shift right