Subtracting 38 from 52 on paper involves borrowing from the next column when the upper digit is smaller. A subtractor circuit follows the same method, with a borrow output taking the place of the carry output of an adder.
Half Subtractor
A half subtractor subtracts a single bit B from a bit A. It gives the difference D and the borrow Bout. The difference is 1 when the two bits differ, so D = A ⊕ B. A borrow is needed only when A is 0 and B is 1, so Bout = A'·B.
Definition: Half subtractor. A combinational circuit that subtracts one binary digit from another and gives a difference bit and a borrow bit.
Table 2.3: Truth table of the half subtractor
| A | B | Difference D | Borrow Bout |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
Full Subtractor
A full subtractor also takes the borrow Bin produced by the column on its right. It subtracts B and Bin from A. The difference is D = A ⊕ B ⊕ Bin and the borrow-out is Bout = A'·B + A'·Bin + B·Bin. The first half subtractor finds A - B, and the second subtracts the incoming borrow from that result. A borrow from either stage means that the next column must lend one unit, so the two borrows are combined by an OR gate. Chaining full subtractors in this way subtracts numbers of any length.
Table 2.4: Comparison of adders and subtractors
| Circuit | Outputs | Equations |
|---|---|---|
| Half adder | Sum, Carry | S = A xor B, C = AB |
| Full adder | Sum, Carry out | S = A xor B xor Cin |
| Half subtractor | Difference, Borrow | D = A xor B, Bout = A'B |
| Full subtractor | Difference, Borrow out | D = A xor B xor Bin |
Example 2.2: Subtracting with a full subtractor
Problem: Find A - B - Bin for A = 0, B = 1 and Bin = 1.
Solution:
- Difference D = 0 ⊕ 1 ⊕ 1 = 0.
- Borrow-out = A'B + A'Bin + B·Bin = 1 + 1 + 1, which is 1.
- In ordinary arithmetic 0 - 1 - 1 = -2. Borrowing 2 from the next column gives 2 - 2 = 0.
Result: D = 0 and Bout = 1.
def fs(a, b, bin_):
d = a ^ b ^ bin_
bo = ((1 - a) & b) | ((1 - a) & bin_) | (b & bin_)
return d, bo
print(fs(0, 1, 1), fs(1, 0, 1))
Output
(0, 1) (0, 0)
Common mistakes
- Using the carry equation of an adder for the borrow output.
- Forgetting that the borrow passes to the next column on the left.
- Writing the borrow of a half subtractor as A·B' instead of A'·B.
Key takeaways
- Half subtractor: D = A ⊕ B and Bout = A'B.
- A borrow occurs when a larger bit is subtracted from a smaller one.
- The full subtractor also accepts the borrow from the previous column.
- Difference equations of adders and subtractors use the same XOR form.
Practice questions
- When does a half subtractor produce a borrow?
- Write the difference equation of a full subtractor.
- What is the difference between a half and a full subtractor?
Answers to the practice questions
- When A is 0 and B is 1.
- D = A XOR B XOR Bin.
- A full subtractor also takes the borrow-in from the previous stage.
Sources
- Official BCA syllabus Computer Architecture, course code 25BCA401DS02, Unit II
