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

Discussion

Bitwise | can be used to set a bit in number.

  • A.Yes
  • B.No

Answer: A

Correct answer: Yes

Setting a single bit is n |= (1 << k). The shift builds a mask with one 1 in position \( k \); OR forces that position to 1 and leaves every other bit unchanged, since \( b \mathbin{|} 0 = b \).

The three basic single-bit operations follow the same shape and differ only in the operator: OR with the mask to set, AND with its complement to clear, and XOR with the mask to toggle. Testing uses AND with the mask without storing the result.

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

Post your comment

Please log in or register to post a comment.