Question 3
Back to Exercise
Which expression is 1 when bit k of an unsigned x is set, and 0 otherwise?
- A x & k
- B (x >> k) & 1u Correct
- C x | (1u << k)
- D x ^ k
Correct Answer: Option B
Shifting right by k brings bit k to position 0, and & 1u keeps only that bit. x & (1u << k) also works as a true/false test, but gives the bit's value (such as 8), not 1.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!