← Quiz: Bitwise Operators in C: all 15 questions
Quiz: Bitwise Operators in C · Question 5 of 15
Why does (n & (n - 1)) == 0 (with n 0) mean n is a power of two?
Why does (n & (n - 1)) == 0 (with n > 0) mean n is a power of two?
- A.Because n - 1 is always odd
- B.A power of two has exactly one set bit, and n & (n - 1) removes it, leaving 0
- C.Because & works like division
- D.It does not — it tests for even numbers
Answer & explanation
Correct answer: A power of two has exactly one set bit, and n & (n - 1) removes it, leaving 0
Removing the only set bit leaves nothing. Any other positive number still has a bit left.
Can you get the rest right without peeking?
Take the timed Quiz: Bitwise Operators in C quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →