unsigned int v;bool f; f = (v & (v - 1)) == 0;Note that 0 is incorrectly considered a power of 2 here. To avoid this, use:f = v && !(v & (v - 1));
unsigned int v;
ReplyDeletebool f;
f = (v & (v - 1)) == 0;
Note that 0 is incorrectly considered a power of 2 here. To avoid this, use:
f = v && !(v & (v - 1));