Quote:
Originally Posted by GEEK
How to write a C program to find the power of 2 in a normal way and in single step?
|
if((n&(n-1))==0)
printf("The number is a power of two");
Eg:
Consider 8
8---> 1000
7---> 0111
8&7-->0000
Therefore 8 is a power of 2!!
Consider 12
12---> 1100
11---> 1011
12&11-->1000
Therefore 12 is not a power of two