Quote:Original post by EelcoIt can't be, but the lowest signed value only has one bit set (the sign bit) and is thus falsely reported as a power of two.
i dont know how your processor works, but my signed integer types always have been of the 0..127,-128..-1 kind. i dont see how counting bits would work there.
actually, thinking about it, id be curious to know how a signed number could ever possibly hope to be an interger power of two anyway... not going to happen, so its a nonissue.
Detect Power of two
Quote:Original post by doynaxQuote:Original post by EelcoIt can't be, but the lowest signed value only has one bit set (the sign bit) and is thus falsely reported as a power of two.
i dont know how your processor works, but my signed integer types always have been of the 0..127,-128..-1 kind. i dont see how counting bits would work there.
actually, thinking about it, id be curious to know how a signed number could ever possibly hope to be an interger power of two anyway... not going to happen, so its a nonissue.
what do you mean by lowest signed value? -1 has all bits set, and thus is not reported as a power of two, and -128 only has the first bit set, and ignoring the sign, is thus reported correctly.
Quote:Original post by EelcoQuote:Original post by doynaxQuote:Original post by EelcoIt can't be, but the lowest signed value only has one bit set (the sign bit) and is thus falsely reported as a power of two.
i dont know how your processor works, but my signed integer types always have been of the 0..127,-128..-1 kind. i dont see how counting bits would work there.
actually, thinking about it, id be curious to know how a signed number could ever possibly hope to be an interger power of two anyway... not going to happen, so its a nonissue.
what do you mean by lowest signed value? -1 has all bits set, and thus is not reported as a power of two, and -128 only has the first bit set, and ignoring the sign, is thus reported correctly.
Yes, -128 has one bit set, and will be reported as true. However, I think we are restricting ourselves to REAL powers of two. If we weren't then it would be logical to include -64, -16, etc... (which will be reported as false along with all other negative values)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement