Commonly used bit operations in computer programs

  • Commonly used bit manipulations in computer programs:

      • Set the bit at position k to 1 (without changing any other bit)

      • Clear/reset the bit at position k to 0 (without changing any other bit)

      • Flip the bit at position k (i.e.: 0 ⇒ 1 and 1 ⇒ 0) (without changing any other bit)

      • Test if the bit at position k is equal to 0 or 1,

  • We will first study a clumpsy way to:

      • Set the bit at position k to 1

  • Later:

    • Learn better ways to perform bit operations using shift operation