4.5 A 4-Bit Calculator
Now let’s look at the 4-bit calculator, made by lining up four of the previous section’s 1-bit adders side by side. We already know the structure, so if you follow along step by step, it should come together more naturally than you might expect.
Figure 4-6 shows the 4-bit calculator circuit.

Looking at the circuit in Figure 4-6, the first thing that catches your eye is the four small boxes in the middle. Each box is the 1-bit adder circuit we looked at earlier, drawn as a single unit. Grouping a circuit into one unit like this is called modularization, and setting the internal wiring aside for a moment to look only at the inputs, outputs, and function is called abstraction. As long as you know the interface we saw in Section 4.3, you can use the circuit block without knowing what’s inside. In other words, you can imagine that inside each small box is the 1-bit adder circuit from the previous section, made of two AND gates, one OR gate, and two XOR gates. You can also see that this circuit takes one 4-bit number through X3, X2, X1, X0 and another through Y3, Y2, Y1, Y0, and produces one 4-bit output through S3, S2, S1, S0.
In short, the 4-bit adder circuit in Figure 4-6 is four 1-bit adders laid out side by side and connected. The key point is that each 1-bit adder’s Cout (carry output) is connected to the Cin (carry input) of the adder for the next digit up, and this chain of connections is what makes the full 4-bit addition possible.
Does adding 2 (0010) and 4 (0100) with the circuit in Figure 4-6 really give 6 (0110)? Let’s check.
Suppose we input the binary digits 0, 0, 1, 0 for decimal 2 into X3, X2, X1, X0 (that is, apply the corresponding voltages), and 0, 1, 0, 0 for 4 into Y3, Y2, Y1, Y0. Following the circuit slowly, the first 1-bit adder — the rightmost one in the figure — receives X0 (0) and Y0 (0), so it outputs Sum 0 and Cout 0. Note that the Cin of the rightmost adder is always fixed at 0. Its Cout is connected to the Cin of the second 1-bit adder, but its value is 0.
Next, the second adder receives X1 (1), Y1 (0), and a Cin of 0 passed on from the first adder. The result is Sum 1, and Cout (the carry) is also 0, which is passed on to the Cin of the third 1-bit adder it’s connected to.
Following the third and fourth adders the same way, S3, S2, S1, S0 finally come out as 0, 1, 1, 0. That’s 6 in decimal — exactly the result we expected.
This time, let’s trace a subtraction too: 2 − 2, which means adding −2 to positive 2 (0010). As you can see in Table 4-2, −2 is written as 1110 in two’s complement. Let’s input 0, 0, 1, 0 into X3, X2, X1, X0 and 1, 1, 1, 0 into Y3, Y2, Y1, Y0.
The first adder receives X0 (0), Y0 (0), and Cin (0), and outputs Sum 0 and Cout 0. The second adder receives X1 (1), Y1 (1), and Cin (0). 1 + 1 + 0 = 2, which is 10 in binary, so it outputs Sum 0 and Cout 1. In the third adder, the Cin (1) passed on from before is added to X2 (0) and Y2 (1). This is exactly the case we put off in the previous section, where Cin is 1. 0 + 1 + 1 = 2, so it outputs Sum 0 and, again, Cout 1. The last, fourth adder receives X3 (0), Y3 (1), and Cin (1). 0 + 1 + 1 = 2, so it outputs Sum 0 and Cout 1.
In the end, S3, S2, S1, S0 come out as 0, 0, 0, 0. Since we agreed in Section 4.3 to hold the result in four digits too, the top carry-out of 1 isn’t kept. The result is 0000, or decimal 0 — exactly right for 2 − 2. This one circuit is all we need for subtraction as well.
Let’s also wrap up the story we put off earlier. If we compute 7 + 1 with this circuit, we get 0111 + 0001 = 1000. But in Table 4-2, 1000 is −8. The correct answer, 8, falls outside the range −8 to 7 that four-digit two’s complement can represent. The circuit didn’t calculate wrongly; four digits simply can’t represent the correct answer, 8. When a result goes beyond the range it can be held in like this, it’s called an overflow. This is different from the carry we just discarded in 2 − 2. There, even after discarding the carry, the remaining four digits, 0000, were the correct answer; in 7 + 1, the remaining four digits themselves are the wrong value. Many CPUs have a separate indicator (a flag) that signals this situation.
So far, we’ve seen how a 4-bit calculator, built by connecting basic logic circuits made of transistors, adds and subtracts numbers from −8 to 7. If you had the basics down, it probably came together more naturally than you expected. The adders inside real CPUs work on the same principle. They just chain together far more bits — 64, for example — and add techniques that cut the time spent waiting for a carry to ripple through to the last digit, so they calculate much faster.