Method of Complements - Negative Number Representations

Negative Number Representations

The method of complements normally assumes that the operands are positive and that yx, logical constraints given that adding and subtracting arbitrary integers is normally done by comparing signs, adding the two or subtracting the smaller from the larger, and giving the result the correct sign.

Let's see what happens if x < y. In that case, there will not be a "1" digit to cross out after the addition since will be less than . For example (in decimal):

185 (x) - 329 (y)

Complementing y and adding gives:

185 (x) + 670 (nines' complement of y) + 1 ===== 856

This is obviously the wrong answer; the expected answer is -144. But it isn't as far off as it seems; 856 happens to be the ten's complement of 144. This issue can be addressed in three ways:

  • Ignore the issue. This is reasonable if a person is operating a calculating device that doesn't support negative numbers since comparing the two operands before the calculation so they can be entered in the proper order, and verifying that the result is reasonable, is easy for humans to do.
  • Represent negative numbers as radix complements of their positive counterparts. Numbers less than are considered positive; the rest are considered negative (and their magnitude can be obtained by taking the radix complement). This works best for even radices since the sign can be determined by looking at the first digit. For example, numbers in ten's complement notation are positive if the first digit is 0, 1, 2, 3, or 4, and negative if 5, 6, 7, 8, or 9. And it works very well in binary since the first bit can be considered a sign bit: the number is positive if the sign bit is 0 and negative if it is 1. Indeed, two's complement is used in most modern computers to represent signed numbers.
  • Complement the result if there is no carry out of the most significant digit (an indication that x was less than y). This is easier to implement with digital circuits than comparing and swapping the operands. But since taking the radix complement requires adding 1, it is difficult to do directly. Fortunately, a trick can be used to get around this addition: Instead of always setting a carry into the least significant digit when subtracting, the carry out of the most significant digit is used as the carry input into the least significant digit (an operation called an end-around carry). So if yx, the carry from the most significant digit that would normally be ignored is added, producing the correct result. And if not, the 1 is not added and the result is one less than the radix complement of the answer, or the diminished radix complement, which does not require an addition to obtain. This method is used by computers that use sign-and-magnitude to represent signed numbers.....

Read more about this topic:  Method Of Complements

Famous quotes containing the words negative and/or number:

    Parents need to recognize that the negative behavior accompanying certain stages is just a small part of the total child. It should not become the main focus or be pushed into the limelight.
    Saf Lerman (20th century)

    Even in ordinary speech we call a person unreasonable whose outlook is narrow, who is conscious of one thing only at a time, and who is consequently the prey of his own caprice, whilst we describe a person as reasonable whose outlook is comprehensive, who is capable of looking at more than one side of a question and of grasping a number of details as parts of a whole.
    G. Dawes Hicks (1862–1941)