This would normally be done on unsigned integers and is usually coded like this:
v && !(v & (v - 1)); // From "Bit Twiddling Hacks" website

But the OP's code is obviously trying to do it with...