ProgrammingHardGATE CS · Campus placements

Which expression clears the lowest three bits of an unsigned char x?

  1. A. x | 0x9
  2. B. x & ~7
  3. C. x ^ 0x6
  4. D. x & 0x7

Correct answer: B. x & ~7

~7 has ones everywhere except bits 0 to 2, so ANDing keeps all other bits and clears those three. x & 0x7 keeps only those bits.

More C Programming questions

Exams that ask this topic