View Single Post
Old 09-02-08, 09:38 PM   #2 (permalink)
sands7788
Junior Member
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1 sands7788 is on a distinguished road
Re: C language - How to write a C program to find the power of 2 in a normal way and in single step?

Quote:
Originally Posted by GEEK View Post
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
sands7788 is offline   Reply With Quote