Re: testing if just one bit is set...
On Nov 8, 12:02 pm, blargg....@gishpuppy.com (blargg) wrote:
James Kanze wrote:
On Nov 7, 12:01 pm, blargg....@gishpuppy.com (blargg) wrote:
James Kanze wrote:
[...]
but because two's complement is the most natural
representation.
What does "the most natural representation" mean?
Two's complement is the natural way to represent negative
values, since things like add, subtract, multiply (both by a
power of two using a shift, and by an arbitrary value) can use
the same hardware as the unsigned equivalents.
In other words, it's not the most natural, it's the cheapest.
[...]> 2's complement has one very big problem: - INT_MIN isn't
representable.
[...]
How is this a big problem? Since trying to generate a value
outside the range of a signed type is UB, one could just treat
the most negative as UB by making INT_MIN == -INT_MAX.
To begin with, you can't write the value directly as an integral
literal. And you have to special case it in a lot of cases.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34