Re:Issues with porting C++ code to a 64-bit platform
by dschatz on Monday April 01, 2013 @03:55PM
(#5475467)
In 2s complement, the most significant bit is the sign bit. In fact all valid C integer representations have a sign bit.
[ Parent
| on HN ]
Re:Issues with porting C++ code to a 64-bit platform
by cube13 on Monday April 01, 2013 @03:57PM
(#5475485)
Signed integer representations. Unsigned ints do not, and you're given the full range of the integer as valid data.
Re:Issues with porting C++ code to a 64-bit platform
by dschatz on Monday April 01, 2013 @04:09PM
(#5475566)
Yes you're right. I should have been more specific that all signed integers have a sign bit.
Re:Issues with porting C++ code to a 64-bit platform
by MichaelSalib on Monday April 01, 2013 @04:36PM
(#5475749)
This is wrong.
Take an integer value x. Flip the sign bit. Do you now have the value -x? On a 2s complement architecture, you do not. In 2s complement, you have to flip all the bits and add one to get -x.
Re:Issues with porting C++ code to a 64-bit platform
by dschatz on Thursday April 04, 2013 @10:02AM
(#5492679)
Sign bit means one bit represents the sign of the integer which is the case with the most significant bit in 2s complement.
If you flip the sign bit, the sign changes. It does not mean that if you flip the sign, the value is negated.
Re:Issues with porting C++ code to a 64-bit platform
by to3m on Monday April 01, 2013 @04:20PM
(#5475630)
I think his point is that changing a sign bit doesn't affect the absolute value, just its sign. A sign bit has no value itself - it's just a flag. If the representation has a sign bit, you'd have a negative zero.
But the top bit in 2s complement has a value - it's just a negative one (that's large enough to make any value with it set negative). That's not a sign bit! If you change it, the absolute value most definitely changes, and quite substantially.