[prev] 21 [next]

Exercise 3: Bit-manipulation

Assuming 8-bit quantities and writing answers as 8-bit bit-strings ...

What are the values of the following:

  • 25,   65,   ~0,   ~1,   0xFF,   ~0xFF
  • (01010101 & 10101010),   (01010101 | 10101010)
  • (x & ~x),   (x | ~x)
How can we achieve each of the following:
  • ensure that the 3rd bit from the RHS is set to 1
  • ensure that the 3rd bit from the RHS is set to 0