*** Welcome to piglix ***

Nines complement


In mathematics and computing, the method of complements is a technique used to subtract one number from another using only addition of positive numbers. This method was commonly used in mechanical calculators and is still used in modern computers.

The nines' complement of a number is formed by replacing each digit with nine minus that digit. To subtract a decimal number y (the subtrahend) from another number x (the minuend) two methods may be used:

In the first method the nines' complement of x is added to y. Then the nines' complement of the result obtained is formed to produce the desired result.

In the second method the nines' complement of y is added to x and one is added to the sum. The leading digit '1' of the result is then discarded. Discarding the initial '1' is especially convenient on calculators or computers that use a fixed number of digits: there is nowhere for it to go so it is simply lost during the calculation. The nines' complement plus one is known as the tens' complement.

The method of complements can be extended to other number bases (radices); in particular, it is used on most digital computers to perform subtraction, represent negative numbers in base 2 or binary arithmetic and test underflow and overflow in calculation.

The radix complement of an n digit number y in radix b is, by definition, . The radix complement is most easily obtained by adding 1 to the diminished radix complement, which is . Since is the digit repeated n times (because ; see also binomial numbers). The diminished radix complement of a number is found by complementing each digit with respect to (that is, subtracting each digit in y from ).


...
Wikipedia

...