Power of 2
Hello all!
I'd like to ask what is most effective way to check if the given number is power of 2? Thx
Quote:Original post by deks
bool bIsPowerOfTwo = !(n&(n-1));
=[dEkS]=
slight mod:
bool is_pow_of2 = (n != 0 && !(n & (n - 1)));
Quote:Original post by snk_kid
slight mod:bool is_pow_of2 = (n != 0 && !(n & (n - 1)));
Good catch! :)
=[dEkS]=
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement