Houjun Liu

bitmask

bitmasking is a very helpful to create bit vectors.

  • | with a 1-mask is useful to turning things on
  • & with a 0-mask is useful to turning things off (bitvector & not(1-mask))
  • | is useful for set unions
  • & is useful for intersections of bits
  • ^ is useful for flipping isolated bits: 0 is bit preserving, 1 is bit negating
  • ~ is useful for flipping all bits