Skip to main content

Bitwise Operators

Bitwise operators treat a number as a row of binary digits and work on those bits directly:

  • & AND - a result bit is 1 only where both input bits are 1
  • | OR - a result bit is 1 where at least one input bit is 1
  • ^ XOR - a result bit is 1 where the two input bits differ
  • << Zero fill left shift - moves the bits to the left, and zeros fill the empty places on the right
  • >> Signed right shift - moves the bits to the right and drops those that pass the right end, while copies of the leftmost bit fill the empty places on the left