Frederick Gotham schrieb:
Michael Mair posted:
> (3) You assume that there are no padding bits in signed int
that are not also there in unsigned int.
I said it had 32 value bits, not 32 object bits.
Yes. However, only the common range of unsigned int and signed
int is guaranteed to have the same representation.
I do not find anything in the standard against either
signed: sign bit -- four padding bits -- 31 value bits
unsigned: five padding bits -- 31 value bits
or
signed: sign bit -- four padding bits -- 31 value bits
unsigned: four padding bits -- 32 value bits
or
signed: sign bit -- four padding bits -- 31 value bits
unsigned: 36 value bits
or, what you were hoping for
signed: sign bit -- four padding bits -- 31 value bits
unsigned: one value bit -- four padding bits -- 31 value bits
where the above specifies the "bit order" of the representation.
So, without the stipulation that unsigned has one more value
bit than signed int and that that additional value bit is
"in the same place" as the sign bit of the signed int, your
expectations may be off.
You may shift too far for identical numbers of value bits in
the first of the above cases. Or you may fail to set the "sign
bit" in the second case.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.