Understanding ‘2s-Complement’ Notation


The Genesis of an Understanding:

  Two’s complement is a convention for handling negative and positive numbers in binary. Its use simplifies the software rules for addition and subtraction where negative numbers are involved. In university, where its use was needed, I learned the rules and applied them by rote. Personally, I feel much better when I understand things well enough that the derivation of the rules is clear, and they can be redeveloped when needed – but for years, the logic behind 2’s complement escaped me. Then it came to me when my mind was working on computing and surveying in close juxtaposition.

The System:

  Before delving into the complex rules of forming negative numbers by subtracting the value from ‘F…F’, and adding 1, consider what surveyors do, in base-10. Where it is inconvenient, and irrelevant, to make a reference to mean ‘sea-level at …,’ or any other conventional datum, a surveyor may simply choose some convenient point to be a benchmark, and declare its elevation to be 100 feet (or 10, or 100 metres, or some other round, positive, value). This is done with neither care nor worry as to where the zero point of elevation is. All elevations on the plan will be given with respect to the unidentified zero.

  This system, for surveyors, has several advantages. On tiny projects, all numbers on the order of 100 are elevations, because horizontal distances never get that large. There are no negative signs to lose track of, overlook, smear and forget, etc. In calculating differential elevations, the subtraction of negative numbers does not occur, nor do negative results occur when determining new elevations within the system. It is these latter advantages, the simplified math, which we should examine.

  What is the elevation difference between two stations, one at 96' and another at 103'? 103−96=7. What is the elevation 10 feet below 108'? 108−10=98. Those are easy calculations – lots easier than calculating 3 (vs 103) minus a negative 4 (vs 96), or 8−10=−2. And, when the result is written, there is no negative sign to be overlooked. Perceptive readers may note a complication when it comes to multiplication. Not to worry. This will be resolved.

Examining and Making Definitions in the Survey System:

  There are rules for doing math, and we can follow them. Since our original elevation of 100' was a datum, a starting place, it is really our ‘zero.’ (A convention is being adopted: The use of text for numbers; The use of digits for the representation.) In the surveying system six feet above the datum is represented as 106. Seven feet below the datum is 93. It is as if the ‘1’ in the hundreds column were a plus sign, and its absence indicated … well what would it indicate? Its absence indicates negative elevations, but also indicates that to get the elevation you must subtract the number from 100. Is this a complicated interpretation? Is it not much easier to simply use the reference of all numbers to the 100-foot datum?

  At this point, I hope that anyone familiar with 2’s complement notation is either nodding a smile of understanding, or fearing I am making this system just as complex. Please persist. All will be resolved.

Modification of the Surveying System:

  Let us next modify the surveying system. We will retain the usage of base-10, but add in the complication that computers have – a limited number of significant figures. If, instead of defining the datum as 100 we were limited to two significant figures, we would have to call datum, our zero, ‘00.’ (Does the “two digits for a date” problem come to mind?) That would not stop us from using ‘99’ as minus-one, but we would have to make some definitions. 00 through 49 are positive numbers, and their value is the number. 99 and on down, through to 50 are negative, and their value is the number minus 100 (which is negative).

  As long as we do not deal with numbers outside of our range, 50 to 99 to 00 to 49 – minus fifty to minus one to zero to plus forty-nine – as long as we do not try to cross the boundary between 49 and 50 – there is no problem. We simply presume that there are no numbers less than 50 (minus fifty), and no numbers greater than 49 (plus forty-nine). Think of our elevations. Minus fifty feet is very low, forty-nine feet is very high. Or 50 feet is very low, 149 feet is very high. And, if the surveyor were expecting a greater spread of elevations, the initial datum could have been put at 1000, or 10,000.

  If you examine what we have developed you will see that half of the available range of numbers, the half from 00 to 49, is the range of nonnegative numbers (zero and positive). The other numbers, 99 down to 50, are negative.

Multiplication and Division:

  2s-complement has been developed, or rather 9s-complement! The application of the logic to the binary-base system is left to the reader.

  As for coping with multiplication – Just as 95×95=9025 – the right-hand two digits of which are ‘25’ – and −5^2=+25 – which matches – All the other computations work out, as long as one remembers a) the number of significant figures, and b) to check for real over-flow.

  For division, consider the problem ‘What is half of -10’: 'Minus 10' is represented by '90'. On calculating 90/2=45 – one should note the answer of '45' has taken us outside the '50 to 99 to 00 to 49' range. Try: 190/2=95. '95' is used to represent 'minus 5' -- which is the answer.

Converting this System to Base-2:

  In 2s-complement notation you can imagine the zero is shifted, just as it is in surveying. Positive numbers have a leading ‘1’, not displayed. Negative numbers are below the datum – the level that is indicated by the leading ‘1’ that is not displayed, it being beyond the range of displayable-digits. Converting this system to base-2 makes the differentiation between positive and negative easier. The leading digit of positive numbers is 0 (instead of the 0 through 4 we had in base-10). Negative numbers have a 1 in that position (vs 5 through 9). If you want to do relative math on the numbers your self, just prefix an additional significant figure to the number – 1 for positive numbers – 0 for negative numbers, but remember that the is at 100…, just like a surveyor’s datum.


Copyright

This material is Copyright (© 1998, through 2009), Robert W. C. Stevens. Reproduction, with this copyright notice intact, is permitted – but sharing the URL would access the latest, and save a tree, and probably make more sense.


 Robert’s Home Page  The latest public version of this document may be viewed on-line at

http://www.wendygamble.com/RwcS/Guides/Understanding_2s_Compliment.html
 Pleased To Be Of Service, RwcS