Machine-translated by Google. Questions are authored in English.
Top

Discussion

A bit is to be cleared without disturbing the others. The correct line is

  • A.reg ^= (1u << n);
  • B.reg = ~(1u << n);
  • C.reg &= ~(1u << n);
  • D.reg |= (1u << n);

Answer: C

Correct answer: reg &= ~(1u << n);

Shifting one into position and inverting gives a mask with a zero at that bit and ones everywhere else; ANDing with it clears the bit and leaves the rest untouched. OR would set the bit, XOR would toggle it, and plain assignment would destroy every other bit in the register.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.