🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Because n - 1 is always odd
  2. B.A power of two has exactly one set bit, and n & (n - 1) removes it, leaving 0
  3. C.Because & works like division
  4. 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 →