int isPowerOfTwo(unsigned int x){ return ((x != 0) && ((x & (~x + 1)) == x));}
This is really fast. It takes about 6 minutes and 43 seconds to check all 2^32 integers.
int isPowerOfTwo(unsigned int x){ return ((x != 0) && ((x & (~x + 1)) == x));}
This is really fast. It takes about 6 minutes and 43 seconds to check all 2^32 integers.