Bitwise and Shift Operators
Explore how to apply bitwise and shift operators in Dart to process integers at the binary level. Understand binary representations, evaluate logical operators like AND, OR, XOR, and learn how shifts affect values. Discover the reasoning behind negative results from the unary complement operator and how Dart handles signed integers using two's complement.
Bitwise and shift operators perform operations on the individual bits of integer types. Computers store numbers in binary form (using 1s and 0s). We usually see our operands and results displayed in decimal format, but these operators process the underlying binary data.
Types of bitwise and shift operators
Below is a list of the bitwise operators supported by Dart.
Operator | Name | Use |
| Bitwise AND | Evaluates to |
| Bitwise OR | Evaluates to |
| Bitwise XOR | Evaluates to |
| Unary Bitwise Complement | Inverts the bits. Bits that are |
Below is a list of the shift operators supported by Dart.
| Shift Left | Shifts all the bits of its operand to the left by the specified amount. |
| Shift Right | Shifts all the bits of its operand to the right by the specified amount. |
Viewing binary representation
Because Dart prints integers in decimal by default, it can be difficult to visualize how bitwise operators work. We can use the toRadixString method and pass it a base of 2 to see the actual binary representation of our ...