In computers, subtraction is generally carried out by
2’s complement
In digital computers, arithmetic operations like subtraction are fundamental. While addition is straightforward using binary adders, direct subtraction can be complex, especially when dealing with negative numbers.
To simplify the hardware design and allow subtraction to be performed using addition circuits, computers commonly employ a method based on complements. Complement representation allows us to represent negative numbers and perform subtraction by adding the complement of the subtrahend (the number being subtracted) to the minuend (the number from which subtraction is done).
For binary systems (which computers use), the relevant complement methods are 1's complement and 2's complement. For decimal systems, 9's complement and 10's complement are used.
The 1's complement of a binary number is found by inverting every bit (0 becomes 1, and 1 becomes 0). Subtraction is performed by adding the 1's complement of the subtrahend to the minuend. If there is an end-around carry (a carry out of the most significant bit), it is added to the least significant bit of the result.
However, 1's complement has a drawback: it has two representations for zero (+0 and -0), which complicates arithmetic logic.
The 2's complement of a binary number is found by adding 1 to its 1's complement. This is the most widely used method for representing signed numbers and performing subtraction in computers.
To perform subtraction using 2's complement: A - B is calculated as A + (2's complement of B). Any carry generated out of the most significant bit is simply discarded.
Here's why 2's complement is preferred:
Let's illustrate with an example:
Subtract 5 from 8 using 4-bit binary (8 - 5):
Find the 2's complement of 5 (0101):
Now add 8 and the 2's complement of 5:
$$ \begin{array}{@{}c@{\,}c@{}c@{}c@{}c} & 1 & 0 & 0 & 0 & \quad (8) \\ + & 1 & 0 & 1 & 1 & \quad (\text{2's complement of } 5) \\ \hline \text{Carry} \rightarrow & 1 & 0 & 0 & 1 & 1 \end{array} $$The result is 0011 after discarding the carry. 0011 in binary is 3, which is the correct result of 8 - 5.
These are complement methods used in decimal systems, not the binary systems used by typical computers. Therefore, they are not used for subtraction in standard computer arithmetic units.
Based on the efficiency and simplicity of hardware implementation, along with the unique representation of zero, 2's complement is the standard method used in computers for performing subtraction.
| Method | System | How Subtraction A - B is Done | Carry Handling | Zero Representation |
|---|---|---|---|---|
| 1's Complement | Binary | A + (1's complement of B) | End-around carry added | Two ( +0, -0) |
| 2's Complement | Binary | A + (2's complement of B) | Carry discarded | One (0) |
| 9's Complement | Decimal | A + (9's complement of B) | End-around carry added | Two (+0, -0) |
| 10's Complement | Decimal | A + (10's complement of B) | Carry discarded | One (0) |
| Term | Explanation |
|---|---|
| Binary Number System | A base-2 system using only digits 0 and 1, fundamental to computers. |
| Complement | A mathematical operation used to simplify subtraction and represent negative numbers in digital systems. |
| 1's Complement | Inverting all bits of a binary number. |
| 2's Complement | 1's complement plus 1; standard for signed binary arithmetic. |
| Subtrahend | The number being subtracted. |
| Minuend | The number from which another is subtracted. |
The choice of 2's complement for representing signed numbers and performing arithmetic is one of the cornerstones of modern computer architecture. It leads to efficient and fast arithmetic logic units (ALUs) within the CPU.
The range of numbers that can be represented using n bits in 2's complement is from $-(2^{n-1})$ to $(2^{n-1} - 1)$. For example, with 8 bits, numbers from $-(2^{8-1}) = -128$ to $(2^{8-1} - 1) = 127$ can be represented.
Understanding complements is crucial for studying digital logic design, computer organization, and assembly language programming, as arithmetic operations are foundational to how programs execute.
Which of the following pairs of octal and binary numbers are NOT equal?
The greatest negative number which can be stored in a 8-bit register using 2's complement arithmetic is
Which of the following codes is also known as reflected binary code?
What is the octal equivalent of (F3B1)16?
The 1's complement of binary number 10010 is