Which of the following expression is correct to check if a given number N is a power of 2 or not?
(A) N && (N – 1)
(B) N || (N – 1)
(C) N ^ (N – 1)
(D) N & (N – 1)
Answer: (D)
Explanation: If N & (N – 1) gives 0, then the given number is a power of 2 otherwise not.
Quiz of this Question
Article Tags :
Recommended Articles