Quantcast
Channel: How to check if a number is a power of 2 - Stack Overflow
Viewing all articles
Browse latest Browse all 38

Answer by sudeepdino008 for How to check if a number is a power of 2

$
0
0
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.


Viewing all articles
Browse latest Browse all 38

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>