CPP MCQ
Which of these expressions will return true if the input integer v is a power of two?
A)
(~v & (v – 1)) == 0;
B)
(v | (v – 1)) == 0;
C)
(v | (v + 1)) == 0;
D)
(v & (v – 1)) == 0;

Correct Answer : Option (D) :   (v & (v – 1)) == 0;

Explanation : Power of two integers have a single set bit followed by unset bits.