Bitwise operators

  • there are four operators that allow you to manipulate single bits of data. They are called bitwise operators.

Here are all of them:

& (ampersand) - bitwise conjunction; | (bar) - bitwise disjunction; ~ (tilde) - bitwise negation; ^ (caret) - bitwise exclusive or (xor).

& does a bitwise and, e.g., x & y = 0, which is 0000 0000 in binary,
| does a bitwise or, e.g., x | y = 31, which is 0001 1111 in binary,
˜  does a bitwise not, e.g., ˜ x = 240*, which is 1111 0000 in binary,
^ does a bitwise xor, e.g., x ^ y = 31, which is 0001 1111 in binary,
>> does a bitwise right shift, e.g., y >> 1 = 8, which is 0000 1000 in binary,
<< does a bitwise left shift, e.g., y << 3 = , which is 1000 0000 in binary,

Last updated