The radix complement of an n {\displaystyle n} -digit number y {\displaystyle y} in radix b {\displaystyle b} is defined as b n − y {\displaystyle b^{n}-y} . In practice, the radix complement is more easily obtained by adding 1 to the diminished radix complement, which is ( b n − 1 ) − y {\displaystyle \left(b^{n}-1\right)-y} . While this seems equally difficult to calculate as the radix complement, it is actually simpler since ( b n − 1 ) {\displaystyle \left(b^{n}-1\right)} is simply the digit b − 1 {\displaystyle b-1} repeated n {\displaystyle n} times. This is because b n − 1 = ( b − 1 ) ( b n − 1 + b n − 2 + ⋯ + b + 1 ) = ( b − 1 ) b n − 1 + ⋯ + ( b − 1 ) {\displaystyle b^{n}-1=(b-1)\left(b^{n-1}+b^{n-2}+\cdots +b+1\right)=(b-1)b^{n-1}+\cdots +(b-1)} (see also Geometric series Formula). Knowing this, the diminished radix complement of a number can be found by complementing each digit with respect to b − 1 {\displaystyle b-1} , i.e. subtracting each digit in y {\displaystyle y} from b − 1 {\displaystyle b-1} .
The subtraction of y {\displaystyle y} from x {\displaystyle x} using diminished radix complements may be performed as follows. Add the diminished radix complement of x {\displaystyle x} to y {\displaystyle y} to obtain b n − 1 − x + y {\displaystyle b^{n}-1-x+y} or equivalently b n − 1 − ( x − y ) {\displaystyle b^{n}-1-(x-y)} , which is the diminished radix complement of x − y {\displaystyle x-y} . Further taking the diminished radix complement of b n − 1 − ( x − y ) {\displaystyle b^{n}-1-(x-y)} results in the desired answer of x − y {\displaystyle x-y} .
Alternatively using the radix complement, x − y {\displaystyle x-y} may be obtained by adding the radix complement of y {\displaystyle y} to x {\displaystyle x} to obtain x + b n − y {\displaystyle x+b^{n}-y} or x − y + b n {\displaystyle x-y+b^{n}} . Assuming y ≤ x {\displaystyle y\leq x} , the result will be greater or equal to b n {\displaystyle b^{n}} and dropping the leading 1 {\displaystyle 1} from the result is the same as subtracting b n {\displaystyle b^{n}} , making the result x − y + b n − b n {\displaystyle x-y+b^{n}-b^{n}} or just x − y {\displaystyle x-y} , the desired result.
In the decimal numbering system, the radix complement is called the ten's complement and the diminished radix complement the nines' complement. In binary, the radix complement is called the two's complement and the diminished radix complement the ones' complement. The naming of complements in other bases is similar. Some people, notably Donald Knuth, recommend using the placement of the apostrophe to distinguish between the radix complement and the diminished radix complement. In this usage, the four's complement refers to the radix complement of a number in base four while fours' complement is the diminished radix complement of a number in base 5. However, the distinction is not important when the radix is apparent (nearly always), and the subtle difference in apostrophe placement is not common practice. Most writers use one's and nine's complement, and many style manuals leave out the apostrophe, recommending ones and nines complement.
The nines' complement of a decimal digit is the number that must be added to it to produce 9; the nines' complement of 3 is 6, the nines' complement of 7 is 2, and so on, see table. To form the nines' complement of a larger number, each digit is replaced by its nines' complement.
Consider the following subtraction problem:
1. Compute the nines' complement of the minuend (873).
2. Add that to the subtrahend (218).
3. Now calculate the nines' complement of the result
1. Compute the nines' complement of 218, which is 781. Because 218 is three digits long, this is the same as subtracting 218 from 999.
2. Next, the sum of x {\displaystyle x} and the nines' complement of y {\displaystyle y} is taken.
3. The leading "1" digit is then dropped, giving 654.
4. This is not yet correct. In the first step, 999 was added to the equation. Then 1000 was subtracted when the leading 1 was dropped. So, the answer obtained (654) is one less than the correct answer x − y {\displaystyle x-y} . To fix this, 1 is added to the answer.
Adding a 1 gives 655, the correct answer to our original subtraction problem. The last step of adding 1 could be skipped if instead the ten's complement of y was used in the first step.
In the following example the result of the subtraction has fewer digits than x {\displaystyle x} :
Using the first method the sum of the nines' complement of x {\displaystyle x} and y {\displaystyle y} is
The nines' complement of 999990 is 000009. Removing the leading zeros gives 9, the desired result.
If the subtrahend, y {\displaystyle y} , has fewer digits than the minuend, x {\displaystyle x} , leading zeros must be added in the second method. These zeros become leading nines when the complement is taken. For example:
can be rewritten
Replacing 00391 with its nines' complement and adding 1 produces the sum:
Dropping the leading 1 gives the correct answer: 47641.
Main articles: Ones' complement and Two's complement
The method of complements is especially useful in binary (radix 2) since the ones' complement is very easily obtained by inverting each bit (changing '0' to '1' and vice versa). Adding 1 to get the two's complement can be done by simulating a carry into the least significant bit. For example:
becomes the sum:
Dropping the initial "1" gives the answer: 0100 1110 (equals decimal 78)
Main article: Signed number representations
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 < y. In that case, there will not be a "1" digit to cross out after the addition since x − y + b n {\displaystyle x-y+b^{n}} will be less than b n {\displaystyle b^{n}} . For example, (in decimal):
Complementing y and adding gives:
At this point, there is no simple way to complete the calculation by subtracting b n {\displaystyle 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:
The method of complements was used in many mechanical calculators as an alternative to running the gears backwards. For example:
Use of the method of complements is ubiquitous in digital computers, regardless of the representation used for signed numbers. However, the circuitry required depends on the representation:
The method of complements was used to correct errors when accounting books were written by hand. To remove an entry from a column of numbers, the accountant could add a new entry with the ten's complement of the number to subtract. A bar was added over the digits of this entry to denote its special status. It was then possible to add the whole column of figures to obtain the corrected result.
Complementing the sum is handy for cashiers making change for a purchase from currency in a single denomination of 1 raised to an integer power of the currency's base. For decimal currencies that would be 10, 100, 1,000, etc., e.g. a $10.00 bill.
In grade schools, students are sometimes taught the method of complements as a shortcut useful in mental arithmetic.3 Subtraction is done by adding the ten's complement of the subtrahend, which is the nines' complement plus 1. The result of this addition is used when it is clear that the difference will be positive, otherwise the ten's complement of the addition's result is used with it marked as negative. The same technique works for subtracting on an adding machine.
Florida Tech https://cs.fit.edu/~wds/classes/adm/Lectures/TensComplement.pdf ↩
Easy Instructions for Operation the Controlled Key Comptometer, Comptometer Division, Felt and Tarrant Mfg. Co., Chicago, 1917, p. 12 https://ed-thelen.org/comp-hist/Comptometer-instructions.html ↩
Carl Barnett Allendoerfer (1971). Principles of Arithmetic and Geometry for Elementary School Teachers. Macmillan. ↩