651

Bit Twiddling Hacks

http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDivDetermining if an integer is a power of 2unsigned int v; // we want to see if v is a power of 2bool f; // the result goes here f = (v & (v - 1)) == 0;Note that 0 is incorrectly considered a power of 2 here. To remedy this, use:f = !(v & (v - 1)) && v;s.a.m.d. in link
0