Re:Write A Function To Determine If A Number Is A Power Of 2
by nevinera on Monday October 18, 2010 @12:28PM
(#1804090)
Negative numbers cannot be powers of two.
Re:Write A Function To Determine If A Number Is A Power Of 2
by darwinGod on Monday October 18, 2010 @01:26PM
(#1804341)
That'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.
Take the modulus and do the bitwise check!