Open In App

Algorithms Quiz | SP2 Contest 1 | Question 14

Last Updated : 28 Aug, 2018
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads