Electronic – Is 2’s complement the only way that singed binary numbers are represented

binary

I have only seen mention 2's complement practically everytime signed number representation is mentioned. However, I have found that there are other ways to represent signed numbers also, these are 1's complement, excess-k and base -2.

Except 1's complement I do not really understand how the other two work. However, what I want to know is, are these other representations ever used at all? If so, where and why? I know that the strength of 2's complement is that addition and subtraction become the same. However, I am not sure about the strengths of the other mentioned methods.

Best Answer

We all float on again...right back into the land of sign-magnitude numbers!

Twos' complement is almost universally used for integer arithmetic for the exact reasons you stated -- addition and subtraction work the same way, carries behave sensibly, and signed overflow is easy to detect as well.

However, floating point math almost universally uses sign-magnitude representation for the overall number, primarily to ease rounding considerations and remove asymmetries in significand range. The only machines that don't use sign-magnitude representation for floating point are of the prehistoric type (even things like S/360s, VAXen, and Crays that predate IEEE 754 use sign-magnitude FP). However, the ubiquity of sign-magnitude IEEE 754 FP has had an impact on integer arithmetic as well, thanks to Brendan Eich's little project called JavaScript.

You see, JavaScript's only arithmetic type is the IEEE 754 double precision float; thankfully, IEEE 754 floats can represent integers exactly up to the significand width. The one problem with this, though, is that using IEEE 754 floats for integer math means you are stuck with sign-magnitude integer math! That's right, negative integers work differently in JavaScript than in every other modern language. Think about this the next time you hear someone pitching Node.js...