Hubbry Logo
Method of complementsMethod of complementsMain
Open search
Method of complements
Community hub
Method of complements
logo
8 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Method of complements
Method of complements
from Wikipedia
Complement numbers on an adding machine c. 1910. The smaller numbers, for use when subtracting, are the nines' complement of the larger numbers, which are used when adding.

In mathematics and computing, the method of complements is a technique to encode a symmetric range of positive and negative integers in a way that they can use the same algorithm (or mechanism) for addition throughout the whole range. For a given number of places half of the possible representations of numbers encode the positive numbers, the other half represents their respective additive inverses. The pairs of mutually additive inverse numbers are called complements. Thus subtraction of any number is implemented by adding its complement. Changing the sign of any number is encoded by generating its complement, which can be done by a very simple and efficient algorithm. This method was commonly used in mechanical calculators and is still used in modern computers. The generalized concept of the radix complement (as described below) is also valuable in number theory, such as in Midy's theorem.

The nines' complement of a number given in decimal representation 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 leftmost digit '1' of the result is then discarded. Discarding the leftmost '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 overflow in calculation.[1]

Numeric complements

[edit]

The radix complement of an -digit number in radix is defined as . In practice, the radix complement is more easily obtained by adding 1 to the diminished radix complement, which is . While this seems equally difficult to calculate as the radix complement, it is actually simpler since is simply the digit repeated times. This is because

(see also Geometric series Formula). Knowing this, the diminished radix complement of a number can be found by complementing each digit with respect to , i.e. subtracting each digit in from .

The subtraction of from using diminished radix complements may be performed as follows. Add the diminished radix complement of to to obtain or equivalently , which is the diminished radix complement of . Further taking the diminished radix complement of results in the desired answer of .

Alternatively using the radix complement, may be obtained by adding the radix complement of to to obtain or . Assuming , the result will be greater or equal to and dropping the leading from the result is the same as subtracting , making the result or just , 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.

Decimal example

[edit]
Digit Nines'
complement
0 9
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
9 0

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:

  873  [x, the minuend]
- 218  [y, the subtrahend]

First method

[edit]

1. Compute the nines' complement of the minuend (873).

 999 - 873 = 126

2. Add that to the subtrahend (218).

  126  [nines' complement of x = 999 - x]
+ 218  [y, the subtrahend]
—————
  344  [999 - x + y]

3. Now calculate the nines' complement of the result

  344  [result]
  655  [nines' complement of 344 = 999 - (999 - x + y) = x - y, the correct answer]

Second method

[edit]

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 and the nines' complement of is taken.

  873  [x]
+ 781  [nines' complement of y = 999 - y]
—————
 1654  [999 + x - y]

3. The leading "1" digit is then dropped, giving 654.

 1654
-1000  [-(999 + 1)]
—————
  654  [-(999 + 1) + 999 + x - y]

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 . To fix this, 1 is added to the answer.

  654
+   1
—————
  655  [x - y]

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.

Magnitude of numbers

[edit]

In the following example the result of the subtraction has fewer digits than :

  123410  [x, the minuend]
- 123401  [y, the subtrahend]

Using the first method the sum of the nines' complement of and is

  876589  [nines' complement of x]
+ 123401  [y]
————————
  999990

The nines' complement of 999990 is 000009. Removing the leading zeros gives 9, the desired result.

If the subtrahend, , has fewer digits than the minuend, , leading zeros must be added in the second method. These zeros become leading nines when the complement is taken. For example:

  48032  [x]
-   391  [y]

can be rewritten

  48032  [x]
- 00391  [y with leading zeros]

Replacing 00391 with its nines' complement and adding 1 produces the sum:

  48032  [x]
+ 99608  [nines' complement of y]
+     1
———————
 147641

Dropping the leading 1 gives the correct answer: 47641.

Binary method

[edit]
Binary
digit
Ones'
complement
0 1
1 0

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:

  0110 0100  [x, equals decimal 100]
- 0001 0110  [y, equals decimal 22]

becomes the sum:

  0110 0100  [x]
+ 1110 1001  [ones' complement of y = 1111 1111 - y]
+         1  [to get the two's complement = 1 0000 0000 - y]
———————————
 10100 1110  [x + 1 0000 0000 - y]

Dropping the initial "1" gives the answer: 0100 1110 (equals decimal 78)

Negative number representations

[edit]

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

At this point, there is no simple way to complete the calculation by subtracting (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 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.

Practical uses

[edit]
Comptometer from the 1920s, with nines' complements marked on each key

The method of complements was used in many mechanical calculators as an alternative to running the gears backwards. For example:

  • Pascal's calculator had two sets of result digits, a black set displaying the normal result and a red set displaying the nines' complement of this. A horizontal slat was used to cover up one of these sets, exposing the other. To subtract, the red digits were exposed and set to 0. Then the nines' complement of the minuend was entered. On some machine this could be done by dialing in the minuend using inner wheels of complements (i.e. without having to mentally determine the nines' complement of the minuend). In displaying that data in the complement window (red set), the operator could see the nines' complement of the nines' complement of the minuend, that is the minuend. The slat was then moved to expose the black digits (which now displayed the nines' complement of the minuend) and the subtrahend was added by dialing it in. Finally, the operator had to move the slat again to read the correct answer.
  • The Comptometer had nines' complement digits printed in smaller type along with the normal digits on each key. To subtract, the operator was expected to mentally subtract 1 from the subtrahend and enter the result using the smaller digits. Since subtracting 1 before complementing is equivalent to adding 1 afterwards, the operator would thus effectively add the ten's complement of the subtrahend. The operator also needed to hold down the "subtraction cutoff tab" corresponding to the leftmost digit of the answer. This tab prevented the carry from being propagated past it, the Comptometer's method of dropping the initial 1 from the result.[2]
  • The Curta calculator used the method of complements for subtraction, and managed to hide this from the user. Numbers were entered using digit input slides along the side of the device. The number on each slide was added to a result counter by a gearing mechanism which engaged cams on a rotating "echelon drum" (a.k.a. "step drum"). The drum was turned by use of a crank on the top of the instrument. The number of cams encountered by each digit as the crank turned was determined by the value of that digit. For example, if a slide is set to its "6" position, a row of 6 cams would be encountered around the drum corresponding to that position. For subtraction, the drum was shifted slightly before it was turned, which moved a different row of cams into position. This alternate row contained the nines' complement of the digits. Thus, the row of 6 cams that had been in position for addition now had a row with 3 cams. The shifted drum also engaged one extra cam which added 1 to the result (as required for the method of complements). The always present ten's complement "overflow 1" which carried out beyond the most significant digit of the results register was, in effect, discarded.

In computers

[edit]

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:

  • If two's complement representation is used, subtraction requires only inverting the bits of the subtrahend and setting a carry into the rightmost bit.
  • Using ones' complement representation requires inverting the bits of the subtrahend and connecting the carry out of the most significant bit to the carry in of the least significant bit (end-around carry).
  • Using sign-magnitude representation requires only complementing the sign bit of the subtrahend and adding, but the addition/subtraction logic needs to compare the sign bits, complement one of the inputs if they are different, implement an end-around carry, and complement the result if there was no carry from the most significant bit.

Manual uses

[edit]

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 school education

[edit]

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.

See also

[edit]

References

[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
The method of complements is a technique in arithmetic for performing subtraction by adding the complement of the subtrahend to the minuend, thereby replacing direct subtraction with addition and simplifying the process, especially for large numbers or in systems where addition is more efficient than subtraction. In decimal arithmetic, it typically involves the nines' complement (subtracting each digit from 9) or tens' complement (nines' complement plus 1), resulting in a sum that exceeds a power of 10, from which the leading 1 is discarded to obtain the difference. For example, to compute 653 - 372, the tens' complement of 372 is 628; adding gives 1281, and discarding the leading 1 yields 281. Originating in manual calculation methods documented as early as 1478 in the Treviso Arithmetic, a Venetian manuscript, the approach gained popularity in 18th- and 19th-century European and American arithmetic texts for its reliance on alone, based on the identity ab=a+(10kb)10ka - b = a + (10^k - b) - 10^k, where kk is the number of digits. It was advocated by educators like Thomas Dilworth in 1802 and appeared in cyphering books, though it declined in use by the early in favor of other algorithms like . In binary arithmetic, the method extends to (inverting all bits) and (ones' complement plus 1), enabling efficient representation of signed integers and subtraction in digital computers by treating negative numbers as their complements. For instance, in an 8-bit system, the twos' complement of -5 (binary 00000101 for +5) is 11111011, and adding it to another number performs subtraction via standard binary addition hardware. This system, proposed in its modern form by in 1945, is the standard for signed integer arithmetic in most processors due to its simplicity and avoidance of separate subtraction circuits.

Basic Concepts

Definition and Purpose

The method of complements is a technique in positional numeral systems for performing by converting the operation into an equivalent of the complement of the subtrahend to the minuend, yielding a result that equals the base raised to the power of the number of digits plus the desired difference. In this approach, for numbers A and B in base r with n digits, the A - B is computed as A + (r^n - B), which simplifies to r^n + (A - B); the r^n term is then discarded or adjusted to obtain A - B. This method leverages the property that the complement of B is r^n - B, transforming borrowing complexities in direct into straightforward carries. The primary purpose of the method of complements is to simplify arithmetic operations by reducing to , thereby minimizing the need for borrowing in manual calculations and enabling efficient in mechanical and electronic devices. In manual arithmetic, it streamlines computations in systems by using digit-wise complements (such as 9's complement), avoiding tedious adjustments. In , it facilitates hardware design for binary operations, where complements like one's and two's allow uniform circuits to handle both positive and negative values without separate logic, improving speed and simplicity in processors. Historically, the method originated in manual arithmetic as early as the late 15th century, with appearances in texts like the Treviso Arithmetic of 1478, and gained popularity in the 18th and 19th centuries through works by European and American arithmeticians such as Jonathan Butlar in 1785 and Thomas Dilworth in later editions of his 18th-century text up to 1802. It was later adapted for mechanical calculators in the 19th century and electronic computers in the mid-20th century, notably influencing binary representations proposed by John von Neumann in 1945.

Complements in Positional Notation

In positional numeral systems, also known as base-r notation, a number is represented as a sequence of digits where each digit did_i (with 0di<r0 \leq d_i < r) at position ii (starting from 0 for the least significant digit) contributes a value of di×rid_i \times r^i to the total value of the number, which is the sum i=0n1diri\sum_{i=0}^{n-1} d_i r^i for an n-digit number. The r's complement (or radix complement) of a positive integer B represented with n digits in base r is defined as rnBr^n - B, providing a way to represent the negation of B within the fixed n-digit framework. This complement ensures that adding B and its r's complement yields rnr^n, the smallest (n+1)-digit number in base r. The diminished r's complement, also known as the (r-1)'s complement, of B is (rn1)B(r^n - 1) - B, which subtracts B from the largest n-digit number consisting of all (r-1) digits (e.g., all 9s in or all 1s in binary). This is equivalent to subtracting each digit of B from (r-1) individually, digit by digit. Complements facilitate in positional systems by converting it to . For the r's complement, subtracting B from A (both n-digit numbers in base r with A ≥ B) is equivalent to AB=A+(rnB)rnA - B = A + (r^n - B) - r^n; the A+(rnB)A + (r^n - B) produces a result whose most significant digit is 1 (representing the rnr^n term as a carry-out), which is discarded to yield A - B exactly, as the carry-out accounts for the rn-r^n adjustment. For the diminished r's complement, the relation is AB=A+((rn1)B)+1rnA - B = A + ((r^n - 1) - B) + 1 - r^n. The addition A+((rn1)B)A + ((r^n - 1) - B) yields AB+rn1A - B + r^n - 1; when A ≥ B, this produces an end-around carry (a carry-out of 1 from the most significant digit), which is added back to the least significant digit (effectively the +1 adjustment) before discarding the carry-out to obtain . This end-around carry mechanism corrects the -1 offset inherent in the diminished complement, simplifying hardware implementation by reusing circuits without borrowing.

Decimal Complements

Nine's Complement

The nine's complement of a decimal number is computed by subtracting each digit of the number from 9, resulting in a digit-wise operation that transforms the original digits accordingly. For example, the nine's complement of 123 is 876, as 9-1=8, 9-2=7, and 9-3=6. This method applies to numbers with a fixed number of digits, typically padded with leading zeros if necessary to maintain consistency in positional notation. Mathematically, the nine's complement of a number BB with nn digits is given by the formula 10n1B10^n - 1 - B, which yields 9999999\ldots9 (n nines) minus BB. This represents the diminished radix complement in base 10, distinct from the full radix (ten's) complement by exactly 1. In the subtraction process using the nine's complement, the minuend AA is added to the nine's complement of the subtrahend BB. If the addition produces a carry-out from the most significant digit, this carry is discarded, and 1 is added to the remaining n-digit result (equivalent to an end-around carry added to the least significant digit). For instance, to compute 718 - 123: the nine's complement of 123 is 876; adding 718 + 876 = 1594; discarding the carry-out 1 leaves 594, and adding 1 yields 595, the correct result. This approach converts subtraction into an addition operation, simplifying manual or mechanical calculations. The nine's complement method offers advantages such as straightforward digit-wise computation without requiring an initial borrow, making it suitable for early computing devices and hand calculations in systems. However, it has limitations, including the need for a final adjustment step via the end-around carry, which introduces potential complexity and error in implementation; additionally, it is not self-correcting for cases where the result is negative, requiring further complementation to interpret the outcome properly.

Ten's Complement

The ten's complement, also known as the complement in base-10 arithmetic, represents the value 10nB10^n - B for an nn-digit number BB, where nn is the fixed number of digits in the system. This method provides a true complement that aligns with modulo 10n10^n, enabling efficient representation of negative numbers without an explicit . To compute the ten's complement of a number BB, first obtain the nine's complement by subtracting each digit of BB from 9, then add 1 to the result. For example, the three-digit number 123 has a nine's complement of 876, and adding 1 yields the ten's complement of 877. This process, equivalent to the formula 10nB10^n - B, was historically implemented in early computers to handle signed arithmetic. In subtraction using the ten's complement, the minuend is added to the ten's complement of the subtrahend; the result includes a leading carry (equivalent to 10n10^n) that is discarded to obtain the difference. This approach leverages the modular property where ABA+(10nB)(mod10n)A - B \equiv A + (10^n - B) \pmod{10^n}, simplifying hardware design for addition-only circuits. The ten's complement offers advantages over the nine's complement by eliminating the need for a final adjustment in subtraction results, as the complement directly produces the correct magnitude without end-around carry propagation. It is particularly useful in algorithms involving by complements, such as certain division routines, where the true complement facilitates precise calculations. This method is preferred for larger numbers or when integrating with operations like division in -based systems, as it maintains consistency in fixed-digit representations and reduces computational overhead in mechanical or early electronic calculators.

Subtraction Examples

To illustrate the application of the nine's complement in , consider the example of subtracting 12 from 15, assuming a two-digit representation for consistency. First, pad the subtrahend to two digits if necessary and compute its nine's complement by subtracting each digit from 9: the nine's complement of 12 is 87 (9-1=8, 9-2=7). Add this complement to the minuend: 15 + 87 = 102. Since there is an end-around carry (the leading 1), drop it to obtain 02 and add the carry 1 to the least significant digit, yielding 03, which is the correct difference of 3. This process involves padding both numbers to the same length to ensure uniform digit handling, performing the addition column by column (with carries propagating right to left), and applying the end-around adjustment only if a carry overflows from the most significant digit. The nine's complement method thus transforms subtraction into addition while accounting for the diminished radix complement's properties. For the ten's complement, the procedure is similar but uses the radix complement, which simplifies the final adjustment by discarding any leading carry without end-around addition. Using the same example, compute the ten's complement of 12 by taking its nine's complement (87) and adding 1, resulting in 88. Add this to 15: 15 + 88 = 103. Discard the leading carry 1, leaving 03 as the result, again confirming the difference of 3. A larger-scale demonstration is subtracting 857 from 2146, padded to four digits: the ten's complement of 0857 is 9143 (obtained as 9999 - 857 + 1, or equivalently 10000 - 857). Adding 2146 + 9143 = 11289; discard the leading 1, yielding 1289, the correct difference. When the minuend is smaller than the subtrahend, such as 12 - 15, the produces no overflow carry, indicating a negative result. For nine's complement: 12 + 84 (nine's of 15) = 96; take the nine's complement of 96 (03) to get -3. For ten's complement: 12 + 85 (ten's of 15) = 97; take the ten's complement of 97 (03) to get -3. In both cases, the absence of overflow signals the need to complement the result and interpret it as negative. The complement methods preserve the scale of numbers by operating within a fixed digit length (e.g., n digits represent values from 0 to 10^n - 1), ensuring the result remains bounded and aligned with the original numeral system's capacity without requiring variable-length adjustments.

Binary Complements

One's Complement

The one's complement in binary serves as the diminished radix complement for base 2, analogous to the nine's complement in decimal notation. It is computed by inverting all bits of a binary number, changing each 0 to 1 and each 1 to 0. For example, in a 3-bit representation, the binary number 101 (decimal 5) has one's complement 010 (decimal 2). Mathematically, for an n-bit BB, the one's complement B~\tilde{B} is given by the B~=2n1B.\tilde{B} = 2^n - 1 - B. This operation produces a value that, when added to BB, yields 2n12^n - 1 (all bits set to 1). In the context of using one's complement arithmetic, the process involves adding the one's complement of the subtrahend to the minuend. If a carry is generated out of the most significant bit, it is added back to the least significant bit in an end-around carry step to ensure correct results. This method converts into an operation, leveraging binary adders. A key advantage of one's complement in binary systems is the simplicity of the bitwise NOT operation for negation, which can be efficiently implemented in hardware using basic inverter gates. However, it has notable limitations, including dual representations for zero—all zeros (000...) for positive zero and all ones (111...) for negative zero—which can complicate equality checks and arithmetic consistency. Additionally, the requirement for end-around carry introduces extra hardware or processing steps, particularly challenging for non-integer operations.

Two's Complement

The two's complement is a binary method analogous to the ten's complement in decimal, serving as the standard representation for signed integers in modern computing due to its efficiency in arithmetic operations. It provides a straightforward way to encode negative numbers such that addition and subtraction can be performed uniformly using the same hardware circuitry. To compute the two's complement of a positive binary number B with n bits, one inverts all the bits (replacing 0s with 1s and 1s with 0s) and then adds 1 to the result; this process is equivalent to adding 1 directly to the one's complement of B. For example, for the 4-bit number 0011 (decimal 3), inverting yields 1100, and adding 1 gives 1101, which represents -3 in two's complement. The mathematical formula for the two's complement of B is B=2nB-B = 2^n - B, where the result is taken modulo 2n2^n to fit within n bits. In binary subtraction using two's complement, the subtrahend is replaced by its and added to the minuend; any carry-out bit from the most significant position (overflow) is discarded, yielding the correct n-bit result without additional adjustments. This process simplifies implementation because it treats as addition, eliminating the need for separate subtractor circuits. Key advantages of two's complement include a unique representation for zero (all bits zero, avoiding dual +0 and -0 as in one's complement), no requirement for end-around carry propagation in arithmetic operations (unlike one's complement), and seamless integration of addition and subtraction into a single adder mechanism. These properties make it particularly suitable for hardware efficiency and algorithmic simplicity. The method was adopted in early computers such as the EDSAC, which became operational in 1949, for its computational simplicity in handling signed binary arithmetic.

Binary Subtraction Process

Binary subtraction using the method of complements transforms the operation into an addition by adding the minuend to the complement of the subtrahend, leveraging binary addition hardware for efficiency.University of Wisconsin-Madison CS354 Lecture Notes This approach applies to both one's and two's complement systems, with differences in complement computation and result adjustment. In one's complement , the subtrahend is negated by inverting all its bits to obtain its one's complement. The minuend is then added to this complement using standard binary addition, including carry propagation from right to left. If a carry is generated out of the most significant bit (MSB), it is added back to the least significant bit (LSB) of the result in a known as end-around carry; the result is then truncated to the original bit width. Bit with leading zeros may be applied to ensure uniform length during addition. For example, consider subtracting 0011₂ (3₁₀) from 1010₂ (10₁₀) in 4 bits:

1010 (minuend: 10₁₀) + 1100 (one's complement of 0011₂) ------- 10110 (sum with carry-out 1)

1010 (minuend: 10₁₀) + 1100 (one's complement of 0011₂) ------- 10110 (sum with carry-out 1)

Applying end-around carry: Take the 4-bit result 0110₂ and add 1 to the LSB, yielding 0111₂ (7₁₀), which is correct. If the final MSB is 1, the result indicates a negative value, whose magnitude is obtained by taking the one's complement of the result.University of Wisconsin-Madison CS354 Lecture Notes Overflow occurs if the signs of the operands match but differ from the result's sign, potentially leading to incorrect representation in the given bit width. In two's complement subtraction, the subtrahend is negated by computing its two's complement—invert all bits and add 1. The minuend is added to this value, with carries handled as in binary addition. Any carry out from the MSB is simply discarded, and the remaining bits form the result. Using the same example:

1010 (minuend: 10₁₀) + 1101 (two's complement of 0011₂) ------- 10111 (sum with carry-out 1)

1010 (minuend: 10₁₀) + 1101 (two's complement of 0011₂) ------- 10111 (sum with carry-out 1)

Discarding the carry-out gives 0111₂ (7₁₀). As with one's complement, an MSB of 1 in the result signifies a negative number. Overflow is detected similarly: if both operands have the same sign but the result does not, the operation has overflowed.University of Wisconsin-Madison CS354 Lecture Notes Two's complement subtraction is generally more efficient than one's complement due to the absence of end-around carry, simplifying hardware implementation by avoiding additional logic for carry recirculation and reducing the steps in the arithmetic unit.MacSorley, J.R. (1961). High-Speed Arithmetic in Binary Computers. Proceedings of the IRE, 49(1), 67-91. This efficiency has made two's complement the dominant choice in modern computing systems for signed binary arithmetic.

Negative Number Representation

One's Complement Encoding

In one's complement encoding, positive integers are represented using their standard unsigned within a fixed number of bits, while negative integers are formed by inverting (complementing) every bit of the binary representation of their . For example, in a 4-bit , the positive number 5 is encoded as 0101, so -5 is represented as 1010, the bitwise inversion of 0101. This method, which derives from the bitwise NOT operation on the positive counterpart, allows for a symmetric treatment of positive and negative values around zero, though with notable limitations. For an nn-bit fixed-width , one's complement encoding supports integers in the range from (2n11)-(2^{n-1} - 1) to +(2n11)+(2^{n-1} - 1), providing 2n12^n - 1 unique nonzero values but including two distinct representations for : the all-zero bit pattern (000...0) for positive and the all-one bit pattern (111...1) for negative . This dual arises because the bitwise complement of is all ones, which interprets as -0 under the encoding scheme. The range symmetry means, for instance, a 4-bit can represent values from -7 to +7, excluding a representation for -8 that would be available in other . Arithmetic operations in one's complement systems rely on standard binary addition, but to correctly handle the dual zero and ensure additive inverses sum to zero, any carry generated from the most significant bit must be rotated back (added) to the least significant bit in an "end-around carry" step. This adjustment compensates for the representation's quirks, such as when adding a number and its negative complement, which might otherwise yield -0 instead of +0 without the carry restoration. Despite its simplicity in negation via bit inversion, one's complement encoding has key drawbacks that limit its practicality: the dual zeros waste one of the 2n2^n possible bit patterns and introduce inconsistencies in zero-handling during computations or s, while magnitude between numbers requires extra logic to account for the inverted bits of negatives, making it less efficient than alternatives. These issues, including the added hardware complexity for end-around carry, contributed to its decline in favor. Historically, one's complement was employed in pioneering machines like the from 1964, but it has been largely supplanted in contemporary architectures.

Two's Complement Encoding

Two's complement encoding represents signed integers in binary by treating positive numbers as their standard binary equivalents and deriving negative numbers from the bitwise inversion (one's complement) of the followed by the addition of 1. For instance, the positive 5 in 4 bits is 0101; to encode -5, invert the bits to 1010 and add 1, yielding 1011. This process ensures that the negative value, when added to its positive counterpart, results in zero ( the bit width), facilitating arithmetic operations. In an n-bit two's complement system, the representable range spans from -2^{n-1} to 2^{n-1} - 1, providing 2^n distinct values with a single representation for . The most significant bit (MSB) serves as the indicator: 0 denotes non-negative values, while 1 indicates negative values, allowing straightforward by replicating the MSB to fill higher bits when expanding to more bits without altering the numerical value. This encoding offers key advantages in hardware implementation, including uniform treatment of addition and subtraction through the same adder circuitry, regardless of operand signs, and the absence of dual zero representations that complicate end-around carries in alternative systems. became the dominant standard for signed integer representation in computing hardware starting in the , notably with IBM's System/360 architecture, which prioritized these efficiencies for scalable .

Comparison of Systems

The one's complement system exhibits symmetry around zero, supporting an equal number of positive and negative values within its range, though this comes at the cost of dual representations for zero (all bits zero and all bits one). In contrast, the two's complement system is asymmetric, providing a single representation for zero and accommodating one additional negative value compared to the number of positive values, which extends the range for negative numbers without redundancy. Regarding hardware implementation, one's complement addition necessitates end-around carry logic to handle overflow bits fed back into the least significant bit, complicating and increasing propagation delays in adders. Two's complement, however, leverages simple ripple-carry adders for both and , as is achieved by inversion plus one, enabling uniform arithmetic operations without special carry handling. For error detection, one's complement checksums offer marginally superior performance over two's complement variants, particularly in capturing carry-out effects for better bit mixing and detection of certain multi-bit errors, with simulated undetected error fractions around 1.52% versus 1.57% for 32-bit checksums on 1024-bit datawords. This advantage stems from the system's handling of inverted representations, though both maintain a of 2 and are generally outperformed by cyclic redundancy checks in robust error coverage. Adoption trends reflect these trade-offs, with one's complement largely phased out in general-purpose by the late due to its hardware inefficiencies and zero ambiguity, while became the dominant standard for its simplicity and efficiency in arithmetic units. Today, is universally employed in major CPU architectures, including x86 and , supporting seamless signed operations across billions of devices. One's complement remains relevant in select specialized or legacy environments, such as mainframe systems, where it continues to underpin arithmetic operations in mission-critical applications despite the broader shift to .

Applications

In Computing Hardware

In computing hardware, the method of complements, particularly , is integral to (ALU) design for efficient operations. Subtractors in ALUs are typically implemented using by converting the subtrahend to its —achieved via an inverter circuit to flip the bits followed by adding 1 through a carry-in signal—allowing to be performed as without dedicated subtractor hardware. This approach simplifies circuit complexity and reduces gate count, as the same circuitry handles both and . Two's complement is predominantly used for fixed-point integer arithmetic in hardware, enabling seamless representation and operations on signed values across various bit widths. In contrast, floating-point units (FPUs) generally employ sign-magnitude representation for the (mantissa), though arithmetic operations on the mantissa may involve complement-based adjustments during alignment and normalization for . This distinction optimizes precision and range in floating-point formats like , where complements are less central to the core representation but support intermediate computations. Overflow detection in two's complement arithmetic is handled by comparing the carry into the (most significant bit) with the carry out of the ; an overflow occurs if these carries differ, signaling a result outside the representable range. This method, implementable with simple XOR logic on the carry signals, ensures reliable setting in ALUs without additional computational overhead. In modern processors, underpins signed integer operations across 8-bit, 16-bit, 32-bit, and 64-bit widths, as seen in architectures where instructions like ADD and SUB treat operands in this format. SIMD extensions, such as SSE and AVX, extend this to vectorized computations, applying to multiple lanes simultaneously for parallel signed arithmetic in applications like and scientific computing. The evolution of complement methods in hardware traces from early vacuum-tube machines like (1945), which used decimal ring counters rather than binary complements, to transistor-based systems in the that adopted binary representations. John von Neumann's 1945 proposal for in the design marked a pivotal shift, enabling efficient signed arithmetic and becoming the standard by the era. With the advent of very-large-scale integration (VLSI) in the and beyond, scaled to complex ALUs in microprocessors, while one's complement persists in niche areas like network protocols for checksum computations in IP, TCP, and UDP via one's complement summation.

Manual Calculation Techniques

The method of complements has been employed in manual arithmetic to simplify subtraction by converting it into an addition operation, thereby avoiding the need for borrowing in multi-digit calculations. In this technique, known historically as the complementary method, the subtrahend is replaced by its ten's complement relative to a power of ten, such as 1000 for three-digit numbers. For instance, to compute 1000 - 456 manually, one first finds the ten's complement of 456 by subtracting each digit from 9 (yielding 543) and adding 1 (resulting in 544), then adds 544 to 1000 to obtain 1544, with the final result being 544 after discarding the leading 1. This approach, popular in 18th-century America for its efficiency in eliminating borrowing steps, was documented in arithmetic texts as a practical alternative to traditional long subtraction. Mechanical desk calculators from the mid-20th century, such as the Friden STW series introduced in the , integrated nine's complement mechanisms to automate without complex borrowing logic. These devices, designed for heavy computational loads in and , used internal gears and dials to add the nine's complement of the subtrahend, displaying the result directly while handling carries automatically. Similarly, portable models like the from the employed ten's complements by adding a string of 9s minus the subtrahend, simplifying the mechanical design and enabling rapid successive operations. Complements also aided verification in multiplication and division, particularly through the "casting out nines" technique, which uses the nine's complement to check computational accuracy by ensuring the (sum of digits 9) remains consistent before and after operations. Originating in ancient around 950 CE and spreading to by the , this method was included in the first printed Western arithmetic book, the Treviso Arithmetic of 1478, as a quick error-detection tool for manual calculations in commerce. Historical manual tools incorporated complements to streamline arithmetic. On the abacus, particularly the Japanese soroban, subtraction often relies on 5-complements (pairs summing to 5) for single beads or 10-complements (summing to 10) for borrowing across columns, allowing users to add the complement instead of directly subtracting. In modern mental math, ten's complements serve as a niche trick for quick approximations or exact subtractions near powers of ten, such as finding 1000 - 456 by mentally adding the complement 544 to reach 1000 and adjusting for the base. This leverages the same principle for rapid estimation in everyday scenarios, like budgeting or quick checks, without paper.

Role in Education

The method of complements is introduced in elementary school subtraction units to foster fluency and conceptual understanding, particularly in curricula aligned with standards like the U.S. State Standards for Mathematics, where it appears in grades 1 through 3 under operations and algebraic thinking domains. For instance, students learn to use complements to 10 for problems within 20, such as decomposing 13 - 4 as (10 + 3) - 4 = 10 - 1 = 9, which demonstrates the inverse relationship between and without relying on counting back. Curriculum resources often include worksheets focused on 9's complements for quick mental checks and to avoid the confusion of borrowing in early , such as finding the complement of a digit to 9 to verify results or simplify calculations. This approach helps young learners practice place value by emphasizing how digits relate within base-10 structures, reducing errors in multi-digit problems. Historically, the method featured prominently in 19th-century arithmetic texts for mental math training, as seen in works like those by Thomas Dilworth (1802 edition), where it was taught as an alternative to borrowing by adding the complement of the subtrahend to the minuend and adjusting for the base. Its use declined mid-20th century with the rise of calculators and emphasis on standard algorithms, but it has been revived in modern education to promote deeper and strategic flexibility. The pedagogical benefits include reinforcing place value concepts and serving as a bridge to binary representations in curricula, where complements underpin negative number encoding. However, coverage gaps persist in many modern programs that prioritize direct subtraction algorithms, leading to uneven global implementation; for example, Asian abacus training programs place greater emphasis on complementary techniques for rapid calculation, enhancing visuospatial skills.

References

Add your contribution
Related Hubs
User Avatar
No comments yet.