Re:Should I Use Signed or Unsigned Ints? (Part 2)
by mcshicks on Tuesday September 01, 2015 @11:58PM
(#10157350)
One thing about two's complement representation is the representation is asymmetric, you have one more negative number, i.e. 0x8000 for a 16 bit signed number is negative (unsigned) 0x8000. So a function like absolute value if it returns a signed integer cannot handle all possible input values. I think if you do any numeric processing using fixed point arithmetic you simply need to know the range is asymmetric for two's complement rather than trying to pick a scheme like always using signed or unsigned.
[ Parent
| on HN ]
Re:Should I Use Signed or Unsigned Ints? (Part 2)
by qznc on Wednesday September 02, 2015 @06:27AM
(#10158340)
There is no "two's complement" in C. The representation of signed integers is implementation-defined. This is one reason why C has undefined behavior.
Imho it does not make sense anymore, since practically all hardware uses two's complement these days. If the standard would declare two's complement for signed integers, then shift-left would always have defined behavior, for example.