The method of complements normally assumes that the operands are positive and that
y ≤
x, 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 x-y+b^n will be less than b^n. For example, (in decimal): 185 [x] - 329 [y] Complementing
y and adding gives: 185 [x] + 670 [nines' complement of y] + 1 ————— 856 At this point, there is no
simple way to complete the calculation by subtracting b^n (1000 in this case); one cannot simply ignore a leading 1. The expected answer is −144, which isn't as far off as it seems; 856 happens to be the ten's complement of 144. This issue can be addressed in a number of 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. • Use the same method to subtract 856 from 1000, and then add a negative sign to the result. • Represent negative numbers as radix complements of their positive counterparts. Numbers less than b^n/2 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
y ≤
x, 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. ==Practical uses==