C/C++ : Find if the given number is a power of 2.
Solution stolen from here [flipcode.com]:
inline bool isPowerOf2(unsigned x) { if (x<1) return false; return (x&(x-1))==0;}
Since the most beautiful solution has already been found, I don't even bother to find something else.

0 Comments:
Post a Comment
<< Home