[prev] 17 [next]

Bitwise AND

The & operator
  • takes two values (1,2,4,8 bytes), treats as sequence of bits
  • performs logical AND on each corresponding pair of bits
  • result contains same number of bits as inputs
Example:

  00100111           AND | 0  1
& 11100011           ----|-----
  --------             0 | 0  0
  00100011             1 | 0  1

Used for e.g. checking whether a bit is set