Binary Subtraction with Two's Complement and the 74283
Learn to subtract binary numbers with two's complement, build an adder subtractor from a 74283 and XOR gates, and read the carry and the sign of the result.
Subtraction by adding
A digital circuit does not need a separate subtractor. It can subtract by adding the negative of the number. Computers store negative numbers in two's complement form, so that one adder works for both operations.
To find the two's complement of a binary number, invert every bit, which gives the one's complement, and then add 1. For 4 bits, the number 0101 (5) becomes 1010 and then 1011. So 1011 stands for −5.
The rule
To compute A − B, add A to the two's complement of B.
A − B = A + (B') + 1 B' is B with every bit inverted
With a 74283, connect the inverted B bits to the B inputs and set the carry in C0 to 1. The carry in provides the +1.
Worked examples with 4 bits
First, 7 − 5. Here A = 0111 and B = 0101, so B' = 1010.
0111 + 1010 + 1 (carry in) = 1 0010 carry out = 1, sum = 0010 = 2
The result is 2, and the carry out is 1. Now 5 − 7. Here A = 0101 and B = 0111, so B' = 1000. The sum is 0101 + 1000 + 1 = 01110, with a carry out of 0. The 4 bit result is 1110, which is −2 in two's complement. Its value is found by inverting and adding 1: 0001 + 1 = 0010, so the magnitude is 2.
Reading the carry
In a subtraction made this way, the carry out has the opposite meaning to its use in addition.
- Carry out = 1: no borrow was needed. A is greater than or equal to B, and the result is a positive number in true form.
- Carry out = 0: a borrow was needed. A is smaller than B. The sum shown is the two's complement of the magnitude, so the true result is negative.
To show the magnitude of a negative result, invert the sum and add 1, using a second adder or a lookup.
An adder subtractor
One circuit can do both jobs. Put an XOR gate in front of each B input. One input of every XOR is a control signal M and the other is a bit of B. When M = 0, the XOR passes B unchanged, and the carry in M = 0 gives A + B. When M = 1, the XOR inverts B, and the carry in M = 1 gives A + B' + 1, which is A − B.
This takes one 74283, four XOR gates (one 7486 chip) and a switch. It is the core of the arithmetic unit of a simple computer.
The full subtractor
A full subtractor works column by column in the way you do by hand. It takes A, B and a borrow in Bin, and gives a difference D and a borrow out Bout.
D = A ⊕ B ⊕ Bin Bout = A' · B + (A ⊕ B)' · Bin
The difference output is the same XOR chain as the full adder sum. The borrow is 1 when A is smaller than B, or when A equals B and a borrow comes in. Chaining four full subtractors gives a ripple borrow subtractor.
Range and overflow
Four bits in two's complement represent −8 to +7. Subtracting can overflow, for example 7 − (−1) = 8, which does not fit. Overflow occurs when the carry into the sign bit and the carry out of it differ. Always check the range before trusting the result.
Another example and sign extension
Compute 3 − 6. Here A = 0011 and B = 0110, so B' = 1001. Then 0011 + 1001 + 1 = 1101 with a carry out of 0. The carry says the answer is negative. The value 1101 is −3, since inverting gives 0010 and adding 1 gives 0011.
To use a 4 bit result in a longer register, copy the sign bit into the new top bits. This is sign extension. The 4 bit value 1101 (−3) becomes 11111101 in 8 bits, and 0011 (3) becomes 00000011. Padding with zeros would change −3 into +13, which is wrong.
Try it in the virtual lab
SinBench has free 3D benches and interactive demos for this topic. Open one to try the ideas above with real instruments, no sign up needed.
Full Adder and 4-Bit Binary Adder (74283)
Questions and answers
How do you subtract using two's complement?
Invert every bit of the number being subtracted, add 1, and then add the result to the first number. A binary adder can do this.
What does the carry out mean in a subtraction?
A carry out of 1 means no borrow: A is at least as large as B. A carry out of 0 means the result is negative and appears in two's complement form.
How do you make a 4 bit subtractor with a 74283?
Invert the four B bits, connect them to the B inputs and tie the carry in C0 to 1. The sum outputs then give A − B.
What range does 4 bit two's complement cover?
It covers −8 to +7. The top bit is the sign: 1 means negative.
Related topics
Half Adder, Full Adder and the 74283 4-Bit Adder
Learn how half and full adders add binary numbers, how to build a ripple carry adder, how the 74283 works with its carry in and out, with worked sums.
Digital Logic DesignLogic Gates and Truth Tables: AND, OR, NOT, NAND, NOR, XOR
Learn the seven basic logic gates with truth tables, symbols and expressions, the common TTL chips that hold them and how to read a gate level circuit.
Digital Logic DesignBoolean Algebra and De Morgan's Laws
Learn the Boolean identities, absorption and consensus, and De Morgan's laws, with worked simplification examples and truth table proofs you can check.