bool ispowerof2(unsigned int x) {
return x && !(x & (x - 1));
}
Please note that the bit-bit of the power of two has the form 10 ... 0, and a number from a number equal to one less is 011 ... 1.
As for your code:
for( i=0, flag=0, y=1;
y<INT_MAX;
if(flag)break,if(flag)printf("YES"),if(y==x)flag=1,i++,y=pow(2,i)
);
The last part foris illegal.
source
share