4.1 Representing Numbers with 0 and 1: Binary
By combining the logic circuits we saw in Chapter 3, we can now build somewhat more complex circuits — for example, circuits that calculate. But a circuit deals only in 0s and 1s, so how can it handle numbers like 6 or 125? The answer is binary.
The numbers we use in daily life are decimal numbers. As the name suggests, decimal numbers combine ten digits, 0 through 9, to express values such as size, quantity, or weight. All the everyday numbers we see, like 1, 35, and 341, are decimal.
Binary numbers, by contrast, express values by combining just two digits: 0 and 1. In the same way, using the eight digits 0 through 7 gives octal, and using sixteen symbols — the digits 0 through 9 plus the letters A through F — gives hexadecimal.
This way of writing numbers — using a set number of digits and carrying over to the next place once they run out — is called a numeral system (or base). In decimal, the place carries over after 9, giving 10; in binary, it already carries over after 1, giving 10.
Changing the numeral system changes how a number looks, but not its value. Suppose an object weighs 125 g. That 125 is the value written in decimal; the same weight written in binary is 01111101. 125 and 01111101 are the same weight written in two different languages. Just as writing the Korean word for apple, “사과,” as “apple” in English doesn’t change the apple itself, the weight a number refers to stays the same whether it’s written in decimal or binary. Only the notation changes; the value is the same.
Table 4-1 shows a few decimal numbers side by side with the binary numbers that represent the same values. Following the binary column from top to bottom, you can see the rightmost digit alternate between 0 and 1, carrying over to the next place after 1. It’s the same rule by which 9 becomes 10 in decimal.
| Decimal | Binary |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| … | … |
| 5 | 0101 |
| 6 | 0110 |
| … | … |
| 9 | 1001 |
| 10 | 1010 |
Converting a number written in one base into another is called base conversion, and it follows fixed rules. In fact, we already use these rules with decimal numbers: 341 is (3 × 100) + (4 × 10) + (1 × 1), because, from the right, each place stands for a value ten times larger than the one before — 1, 10, 100. Binary works the same way, except that each place doubles — 1, 2, 4, 8. So the binary number 0110 shown in bold in Table 4-1 is (0 × 8) + (1 × 4) + (1 × 2) + (0 × 1) = 6 — decimal 6. There is also a method for converting decimal numbers into binary; sharp-eyed readers may already have guessed the rule from the table.
As this shows, there are many numeral systems that can express the same value. The one chips use is binary. So to understand how a chip calculates, we also need to know how to calculate in binary. Let’s start with addition.
Adding the decimal numbers 6 and 3 gives 9. What happens if we convert the same two numbers into binary and add them? The result will also come out in binary, but converting it back to decimal must give 9. A numeral system is only a way of writing numbers, so the result of a calculation must be the same, too.
Binary addition works the same way as decimal addition: add from the rightmost place, and when a place overflows, carry over to the next. The difference is that, because the only digits are 0 and 1, a place already overflows at 1 + 1. Figure 4-1 shows how 6 (0110) and 3 (0011) are added.

The rightmost place is 0 + 1, so it’s 1. The next place is 1 + 1 = 10, so we leave 0 and carry the 1 to the next place. The third place is 1 + 0 plus the carried 1, which again makes 10, so likewise we leave 0 and carry 1. The last place is 0 + 0 plus the carried 1, which is 1. The result is binary 1001, and converted to decimal that’s (1 × 8) + (0 × 4) + (0 × 2) + (1 × 1) = 9. Simpler than you expected, or a little unfamiliar?
Now that we’ve done addition, it’s time for subtraction. Seen from another angle, subtraction is adding a negative number: 7 − 5 is the same as 7 + (−5). So if we can represent negative numbers in binary, we can subtract using exactly the same addition method we just saw.
There are several ways to represent negative numbers in binary. Let’s first look at the most intuitive one, then move on to the two’s complement method, which overcomes its limitations. For convenience, let’s agree to use 8-digit binary numbers here. Both numbers being added, and the result, are held in 8 digits. Table 4-1 used 4 digits, but adding more 0s in front doesn’t change the value; for example, 5 is 00000101.
The most intuitive approach is to use the leftmost digit as a sign: 0 means positive and 1 means negative. Then −5 becomes 1 0000101. The leading 1 is the sign meaning “negative,” and the remaining seven digits, 0000101, are the magnitude, 5. In the same way, +5 is 0 0000101. This is called the sign-magnitude method.
It’s simple, but there’s a problem. Adding 5 and −5 should give 0, yet adding 00000101 (5) and 10000101 (−5) using the method above gives not 00000000 but 1 0001010 — which, read in sign-magnitude, is decimal −10. As a way of writing negative numbers it looks plausible, but it doesn’t serve our goal of doing subtraction with addition.
The method that solves this problem is two’s complement. Making a negative number in two’s complement takes two steps: 1) flip every digit of the positive number (0→1, 1→0), and 2) add 1. For −5, flip 00000101 (binary 5) to get 11111010, then add 1 to get 11111011. It’s the same −5, but it looks nothing like the sign-magnitude version (1 0000101).
Now let’s add 5 and −5 again. Adding 00000101 (5) and 11111011 (−5) gives the 9-digit result 1 0000 0000. Since we agreed to hold results in 8 digits, the overflowing leading 1 isn’t kept. The remaining eight digits are 00000000 — the 0 we wanted. The same holds for other numbers: when negative numbers are represented in two’s complement, a single addition method handles subtraction accurately as well. Real chips, too, represent negative integers this way in most cases, and the reason is clear: with two’s complement, the addition circuit can also be used for subtraction. With just a simple step to make a number negative, there’s no need to build a separate, large circuit for subtraction. We’ll see this for ourselves when we build a calculator circuit later.
We now know that we can represent numbers with nothing but 0s and 1s, convert them to and from decimal, and even calculate with them. We’ve also seen that if we choose two’s complement to represent negative numbers, addition can handle subtraction too. In the next section, let’s look at how these numbers are connected to the voltages of a real circuit.