3 ms·
In the final version of x&(x-1)==0, one part was overlooked- negative numbers :) Take the modulus and do the bitwise check!
by darwinGod 16y ago
In the final version of x&(x-1)==0, one part was overlooked- negative numbers :)
Take the modulus and do the bitwise check!
- nevinera 16y agoNegative numbers cannot be powers of two.
- darwinGod 16y agoThat's definitely true- but say you want to check for (+/-2)^n, then you would have to deal with negative numbers. If you go by the Two's complement representation, then for a negative number say (-8), because of sign extention, a check for x&(x-1) would fail.