Q7. How to find in one line whether a given number is power of 2 or not?

It seems difficult question for them, who have encountered these type of earlier. This type of question checks your understandings of  bitwise and logical operators. See solution below.

if( num && (num & (num – 1)))


printf(“Number is not the power of two\n”);




printf(“Number is the power of two\n”);


There is may be some good solution, if you have please post here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.