Re: testing if just one bit is set...
On Nov 6, 10:55 pm, Jeff Schwab <j...@schwabcenter.com> wrote:
Juha Nieminen wrote:
Jeff Schwab wrote:
I've only considered it for two's complement.
Exactly how does two's complement representation kick in
with unsigned values?
Are you asking why the representation is relevant? As far as
I know, all of the representations allowed by the Standard are
equivalent for purposes of this discussion.
Yes and no. For signed values, the bit pattern of -n will
depend on the representation. For unsigned values, the standard
defines -i to be 2^n-i (where n is the number of value bits in
the unsigned). Which by a curious bit of chance(:-)) just
happens to correspond to what you'd get for 2's complement
signed values.
The only one I've really considered is two's complement,
though. That doesn't mean I think there's any particular
problem with the other allowed representations, just that I
don't know enough about them to know whether there are any
gotchas.
On thing is immediately certain, the bit pattern of -n will
depend on the representation if the type is signed. Which means
that it probably will not work.
--
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