Chapter Ten

Alternative 10s

Ten is an exceptionally important number to us humans. Ten is the number of fingers and toes most of us have, and we certainly prefer to have all ten of each. Because our fingers are convenient for counting, we humans have developed an entire number system that’s based on the number ten.

A pair of hands with the fingers labeled 1 through 10.

As I discussed in the previous chapter, our conventional number system is called base ten, or decimal. Decimal numbers seem so natural to us that it’s difficult at first to conceive of alternatives. Indeed, when we see 10, we can’t help but think that it refers to this many ducks:

The number one followed by zero equivalent to ten ducks.

But the only reason that the numeral 10 refers to this many ducks is that this many ducks is the same as the number of fingers we have. If human beings had a different number of fingers, the way we counted would be different, and 10 would mean something else. That same numeral 10 could refer to this many ducks:

The number one-zero equivalent to eight ducks.

Or this many ducks:

The number one-zero equivalent to four ducks.

Or even this many ducks:

The number one-zero equivalent to two ducks.

When we get to the point where 10 means just two ducks, we’ll be ready to examine how switches, wires, and lightbulbs can represent numbers, and how relays and logic gates (and by extension, computers) can manipulate numbers.

What if human beings had only four fingers on each hand, like cartoon characters? We probably never would have thought to develop a number system based on ten. Instead, we would have considered it normal and natural and sensible and inevitable and incontrovertible and undeniably proper to base our number system on eight. This is called an octal number system, or base eight.

If our number system were organized around eight rather than ten, we wouldn’t need the symbol that looks like this:

9

Show this symbol to any cartoon character and you’ll get the response, “What’s that? What’s it for?” And if you think about it a moment, we also wouldn’t need the symbol that looks like this:

8

In the decimal number system, there’s no special symbol for ten, so in the octal number system there’s no special symbol for eight.

The way we count in the decimal number system is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and then 10. The way we count in the octal number system is 0, 1, 2, 3, 4, 5, 6, 7, and then what? We’ve run out of symbols. The only thing that makes sense is 10, and that’s correct. In octal, the next number after 7 is 10. But this 10 doesn’t mean the number of fingers that humans have. In octal, 10 refers to the number of fingers that cartoon characters have.

The eight fingers of a cartoon character’s two hands numbered one, two, three, four, five, six, seven, one-zero.

We can continue counting on our four-toed feet:

The eight toes of a cartoon character’s two feet numbered one-one, one-two, one-three, one-four, one-five, one-six, one-seven, two-zero.

When you’re working with number systems other than decimal, you can avoid some confusion if you pronounce a numeral like 10 as one zero. Similarly, 13 is pronounced one three, and 20 is pronounced two zero. To be more precise and really avoid ambiguity, you can say one three base eight or two zero octal.

Even though we’ve run out of fingers and toes, we can still continue counting in octal. It’s basically the same as counting in decimal except that we skip every number that has an 8 or a 9 in it:

0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 40, 41, 42, 43, 44, 45, 46, 47, 50, 51, 52, 53, 54, 55, 56, 57, 60, 61, 62, 63, 64, 65, 66, 67, 70, 71, 72, 73, 74, 75, 76, 77, 100…

That last number is pronounced one zero zero. It’s the number of fingers that cartoon characters have, multiplied by itself.

Nearly a lifetime of familiarity with decimal numbers has conditioned us to expect that certain sequences of digits correspond to specific quantities in the real world. Counting in a different number system is like entering a whole different world. Here are some examples of octal numbers:

  1. The number of dwarfs that Snow White meets is 7, as in decimal.

  2. The number of fingers that cartoon characters have is 10.

  3. The number of symphonies that Beethoven wrote is 11.

  4. The number of fingers that humans have is 12.

  5. The number of months in a year is 14.

If you find yourself mentally converting these octal numbers into decimal, that’s great. It’s a good exercise. For a two-digit octal number that begins with 1, the decimal equivalent is 8 plus the second digit. The number of months in octal is 14, so in decimal it’s 8 plus 4, or 12. Let’s continue:

  1. A baker’s dozen is 15.

  2. The number of days in a fortnight is 16.

  3. The “sweet” birthday celebration is 20.

  4. The number of hours in a day is 30.

  5. The number of letters in the Latin alphabet is 32.

When a two-digit octal number begins with something other than 1, then the conversion to decimal is a little different: You need to multiply the first digit by 8 and then add the second digit. The number of letters in the alphabet is 32 in octal, so in decimal it’s 3 times 8 (or 24) plus 2, which equals 26.

  1. The number of fluid ounces in a quart is 40.

  2. The number of cards in a deck is 4 times 15, or 64.

  3. The number of squares on a chessboard is 10 times 10, or 100.

In decimal, the number of squares on a chessboard is 8 times 8, or 64.

  1. The number of yards in an American football field is 144.

  2. The number of starting women singles players at Wimbledon is 200.

  3. The number of characters in 8-dot Braille is 400.

This list contains several nice round octal numbers such as 100 and 200 and 400. The term nice round number commonly means a number that has some zeros at the end. Two zeros on the end of a decimal number means that the number is a multiple of 100, which is 10 times 10. With octal numbers, two zeros on the end means that the number is also a multiple of 100, but that’s 100 in octal, which is 64 in decimal. The number of starting women singles players at Wimbledon is 128 in decimal, and the number of characters in 8-dot Braille is 256.

The first three chapters of this book explored how binary codes involve powers of two. The number of Morse codes possible with four dots and dashes is 2 to the 4th power, or 16. The number of codes in 6-dot Braille is 2 to the 6th power, or 64. Eight-dot Braille increases the number to 2 to the 8th power, or 256. Anytime we multiply a power of two by another power of two, the result is also a power of two.

The following table shows the first 12 powers of two with the decimal and octal representations:

A table showing powers of two from the first power to the twelfth power. The second column shows the decimal equivalents, 1, 2, 4, 8, 16, and so forth up to 4096, and the third column shows the octal equivalents: 1, 2, 4, one-zero, two-zero, four-zero, one-zero-zero, and so forth up to one-zero-zero-zero-zero.

Because eight is a power of two, the Octal column shows a lot of nice round numbers and therefore suggests a closer relationship to binary codes than is possible with decimal numbers.

The octal system isn’t different from the decimal system in any structural way. It just differs in details. For example, each position in an octal number is a digit that’s multiplied by a power of eight:

A diagram showing how six digits of an octal number correspond (from right to left) to the number of ones, the number of eights, the number of sixty-fours, and so on.

Thus, an octal number such as 3725 can be broken down like so:

3725=3000+700+20+5

This number can also be expressed as the individual digits multiplied by octal powers of eight:

3725=3×1000+7×100+2×10+5×1

Here’s another way of showing it:

3725=3×83+7×82+2×81+5×80

If you work out this calculation in decimal, you’ll get 2005. This is how you can convert octal numbers to decimal numbers.

You can add and multiply octal numbers the same way you add and multiply decimal numbers. The only real difference is that you use different tables for adding and multiplying the individual digits. Here’s the addition table for octal numbers:

An addition table for octal digits.

For example, 5 + 7 = 14. Longer octal numbers can be added the same way as decimal numbers. Here’s a little exercise that looks just like a decimal addition except the numbers are octal. Use the table above to add each column of digits:

135+643¯

Each column of digits adds up to a number greater than octal 7, so each column has a carry to the next column. The result is 1000.

Similarly, 2 times 2 is still 4 in octal. But 3 times 3 isn’t 9. How could it be? Instead, 3 times 3 is 11. You can see the entire octal multiplication table here:

A multiplication table for octal digits.

This table shows that 4 × 6 equals 30, which is 24 in decimal.

Octal is as valid a number system as decimal. But let’s go further. Now that we’ve developed a numbering system for cartoon characters, let’s develop something that’s appropriate for lobsters. Lobsters don’t have fingers exactly, but lobsters of the Homarus americanus species do have pincers at the ends of their two long front legs. An appropriate number system for lobsters is the quaternary system, or base four:

The two pincers of a lobster labeled one, two, three, and one-zero.

Counting in quaternary goes like this: 0, 1, 2, 3, 10, 11, 12, 13, 20, 21, 22, 23, 30, 31, 32, 33, 100, 101, 102, 103, 110, 111, 112, 113, 120, and so forth.

I’m not going to spend much time with the quaternary system, because we’ll be moving on shortly to something much more important. But you can see here how each position in a quaternary number corresponds this time to a power of four:

A diagram showing how six digits of a quaternary number correspond (from right to left) to the number of ones, the number of fours, the number of sixteens, and so on.

The quaternary number 31232 can be written like this:

31232=3×10000+1×1000+2×100+3×10+2×1

Each digit is multiplied by a power of four:

31232=3×44+1×43+2×42+3×41+2×40

If you do the calculations in decimal, you’ll find that 31232 in quaternary is the same as 878 in decimal.

Now we’re going to make another leap, and this one is extreme. Suppose we were dolphins and must resort to using our two flippers for counting. This is the number system known as base two, or binary (from the Latin for two by two). It seems likely that we’d have only two digits, and these two digits would be 0 and 1.

You’ve already seen how 1 and 0 can be used in Boolean algebra to represent True or False, Yes or No, Good Kitty or Not-Quite-Good-Enough Kitty. You can also use these same two digits for counting.

Now, 0 and 1 aren’t a whole lot to work with, and it takes some practice to get accustomed to binary numbers. The big problem is that you run out of digits very quickly. For example, here’s how a dolphin counts using its flippers:

The two flippers of a dolphin labeled one and one-zero.

Yes, in binary the next number after 1 is 10. This is startling, but it shouldn’t really be a surprise. No matter what number system we use, whenever we run out of single digits, the first two-digit number is always 10. In binary we count like this:

0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100,
1101, 1110, 1111, 10000, 10001…

These numbers might look large, but they’re really not. It’s more accurate to say that binary numbers get long very quickly rather than large:

  1. The number of heads that humans have is 1.

  2. The number of flippers on a dolphin is 10.

  3. The number of teaspoons in a tablespoon is 11.

  4. The number of sides to a square is 100.

  5. The number of fingers on one human hand is 101.

  6. The number of legs on an insect is 110.

  7. The number of days in a week is 111.

  8. The number of musicians in an octet is 1000.

  9. The number of innings in a baseball game is 1001.

  10. The number of gallons in a cowboy hat is 1010.

and so forth.

In a multidigit binary number, the positions of the digits correspond to powers of two:

A diagram showing how the six digits of a binary number correspond (from right to left) to the number of ones, the number of twos, the number of fours, and so on.

So anytime we have a binary number composed of a 1 followed by all zeros, that number is a power of two, and the power is the same as the number of zeros. Here’s our expanded table of the powers of two demonstrating this rule:

A table showing powers of two from the first power to the twelfth power. The second column shows the decimal equivalents, 1, 2, 4, 8, and so forth, and the third column shows the octal equivalents: 1, 2, 4, one-zero, two-zero, four-zero, one-zero-zero, and so forth. The fourth column shows the quaternary equivalents: 1, 2, one-zero, two-zero, one-zero-zero, two-zero-zero, and so forth. The final column shows the binary equivalents: one, one-zero, one-zero-zero, one-zero-zero-zero, one-zero-zero-zero-zero, and so forth.

Suppose we encounter the binary number 101101011010. This can be written as:

101101011010=1×100000000000+0×10000000000+1×1000000000+1×100000000+0×10000000+1×1000000+0×100000+1×10000+1×1000+0×100+1×10+0×1

The same number can be written in this simpler way using powers of two:

101101011010=1×211+0×210+1×29+1×28+0×27+1×26+0×25+1×24+1×23+0×22+1×21+0×20

If you just add up the parts in decimal, you get 2048 + 512 + 256 + 64 + 16 + 8 + 2, which is 2906, and that’s the decimal equivalent of the binary number.

To convert binary numbers to decimal more concisely, you might prefer to use a template I’ve prepared:

A template to convert binary numbers to decimal numbers. Eight boxes at the top allow entering a six-digit binary number. These digits are multiplied by 128, 64, 32, 16, 8, 4, 2, and 1, and the products are entered into eight boxes on the bottom. The eight boxes are then totaled to reveal the decimal equivalent.

This template allows you to convert numbers up to eight binary digits in length, but it could easily be extended. To use it, put the binary digits in the eight boxes at the top, one digit to a box. Perform the eight multiplications and put the products in the eight lower boxes. Add these eight boxes for the final result. This example shows how to find the decimal equivalent of 10010110:

A template to convert binary numbers to decimal numbers showing that the binary number one-zero-zero-one-zero-one-one-zero is the equivalent of decimal 150.

Converting from decimal to binary isn’t quite as straightforward, but here’s a template that lets you convert decimal numbers from 0 through 255 to binary:

A template to convert decimal numbers to binary numbers. It consists of eight boxes at the top. Underneath are indications to divide the numbers in the boxes by 128, 64, 32, 16, 8, 4, 2, and 1. Underneath these numbers are eight boxes on the bottom.

The conversion is trickier than it might appear. First, put the entire decimal number (less than or equal to 255) in the box in the upper-left corner:

A template to convert decimal numbers to binary numbers with the decimal number 150 inserted in the upper-left box.

Divide that number by 128 but only to the point where you get a quotient and a remainder: 150 divided by 128 is 1 with a remainder of 22. Put the quotient in the first box on the bottom and the remainder in the next box on top:

A template to convert decimal numbers to binary numbers showing that the decimal number 150 divided by 128 is 1 with a remainder of 22. The 1 is the first digit of the binary result. The 22 goes in the second box on the top.

Now divide 22 by 64, but again, only the first step: Because 22 is less than 64, the quotient is 0 with a remainder of 22. Put the 0 in the second box on the bottom and move the remainder to the next box on the top:

A template to convert decimal numbers to binary numbers showing that the previous remainder of 22 divided by 64 is 0. This becomes the second binary digit of the result. The 22 is then put in the third box at the top for the next division.

Proceed through the template in the same way. Each quotient will be either 0 or 1, so when you’re finished, the boxes at the bottom display a sequence of binary digits:

Template to convert decimal numbers to binary numbers showing the full result of converting decimal 150 to binary.

The binary equivalent of 150 is 10010110.

These conversions between decimal and binary numbers are certainly awkward, so if you ever need to perform them for real, you’ll be pleased to know that both the Windows and the macOS calculator apps have Programmer modes that can do them for you.

The use of binary numbers was not universal in early digital computers. Some of the very first computers were designed and built to use familiar decimal numbers. The Analytical Engine that English mathematician Charles Babbage (1791–1871) designed beginning in the 1830s stored decimal numbers using the positioning of geared wheels. (Unfortunately, he wasn’t able to actually build this machine.) Some of the early working digital computers, such as the Harvard Mark I (first operational in 1944) and the ENIAC (1946), were also built to work with decimal numbers. Some IBM computers manufactured into the 1960s also had architectures based on decimal numbers.

But more than anything else, it’s been binary encodings that have characterized the digital revolution. The simplicity of binary numbers is perhaps most clearly evident in the basic operations of addition and multiplication. This is the part you’re really going to like. Imagine how quickly you could have mastered addition if the only thing you had to memorize was this:

A binary addition table showing that 0 plus 0 equals 0, 0 plus 1 equals 1, and 1 plus 1 equals 10.

Let’s use this table to add two binary numbers:

1100101+011011010011011

Starting at the rightmost column: 1 plus 0 equals 1. Second column from right: 0 plus 1 equals 1. Third column: 1 plus 1 equals 0, carry the 1. Fourth column: the carried 1 plus 0 plus 0 equals 1. Fifth column: 0 plus 1 equals 1. Sixth column: 1 plus 1 equals 0, carry the 1. Seventh column: The carried 1 plus 1 plus 0 equals 10.

The multiplication table is even simpler than the addition table because it can be entirely derived by using two of the very basic rules of multiplication: Multiplying anything by 0 is 0, and multiplying any number by 1 has no effect on the number.

A binary multiplication table showing that 0 times 0 equals 0, 0 times 1 equals 0, and 1 times 1 equals 1.

Here’s a multiplication of decimal thirteen (1101 in binary) by decimal eleven (1011 in binary). I’m not going to show all the steps, but it’s the same process as decimal multiplication:

110100×1011000011010011010000110100010001111

The result in decimal is 143.

People who work with binary numbers often write them with leading zeros (that is, zeros to the left of the first 1)—for example, 0011 rather than just 11. This doesn’t change the value of the number at all; it’s just for cosmetic purposes. For example, here are the first 16 binary numbers with their decimal equivalents:

A table of the first 16 binary numbers from zero-zero-zero-zero to one-one-one-one.

Let’s pause to study this list of binary numbers for a moment. Consider each of the four vertical columns of zeros and ones, and notice how the digits alternate going down the column:

  • The rightmost digit alternates between 0 and 1.

  • The next digit from the right alternates between two 0s and two 1s.

  • The next digit alternates between four 0s and four 1s.

  • The next digit alternates between eight 0s and eight 1s.

This is very methodical, wouldn’t you say? Indeed, this is so methodical that it’s possible to create a circuit that can generate sequences of binary numbers automatically. That’s coming up in Chapter 17.

Moreover, you can easily write the next 16 binary numbers by just repeating the first 16 and putting a 1 in front:

A table of binary numbers corresponding to decimal numbers 16 through 31, from one-zero-zero-zero-zero to one-one-one-one-one.

Here’s another way of looking at it: When you count in binary, the rightmost digit (also called the least significant digit) alternates between 0 and 1. Every time it changes from a 1 to a 0, the digit second to the left (that is, the next most significant digit) also changes, either from 0 to 1 or from 1 to 0. More generally, every time a binary digit changes from a 1 to a 0, the next most significant digit also changes, either from a 0 to a 1 or from a 1 to a 0.

Binary numbers can get very long very quickly. For example, twelve million in binary is 101101110001101100000000. One way to express binary numbers more concisely is to show them in octal. This works well because every three binary digits corresponds to one octal digit:

A table that shows how three-digit binary numbers from zero-zero-zero to one-one-one correspond with octal digits zero through seven.

Take that long binary number for twelve million, for example, and separate it into groups of three starting at the right:

101101110001101100000000

Each group of three binary digits corresponds to an octal digit:

10110111000110110000000055615400

Twelve million in decimal is 55615400 in octal. In Chapter 12, you’ll see an even more concise way of expressing binary numbers.

By reducing our number system to just the binary digits 0 and 1, we’ve gone as far as we can go. We can’t get any simpler without resorting to primitive scratch marks. But what’s most important is that binary numbers allow arithmetic and electricity to be united. Switches, wires, and lightbulbs can all represent the binary digits 0 and 1, and with the addition of logic gates, these numbers can be manipulated. This is why binary numbers have a whole lot to do with computers.

You’ve just seen a little table that shows the correspondence between three-digit binary numbers and their octal equivalents. Using switches, lightbulbs, and logic gates, you can build a circuit that performs this conversion for you:

Images

A circuit to show the octal number 0 through 7 that corresponds to a three-digit binary number set with three switches.

This circuit undoubtedly looks terribly forbidding at first glance, rather like a nightmare assemblage of intersecting highways in a foreign city where all the traffic signs are unreadable. But it’s actually quite methodical. Little dots indicate when wires are connected to each other. Otherwise, the wires are not connected and just overlap.

The circuit begins at the top with three switches to represent a three-digit binary numbers. These switches are closed for 1 and open for 0. This example shows how the binary number 100 is represented. At the bottom are eight lightbulbs labeled 0 through 7. Just one of them lights up depending on what switches are closed:.

It’s probably easier to understand the circuit from the bottom up: Each of the eight lightbulbs at the bottom is powered by a three-input AND gate. The output of the AND gate is 1 only if all three inputs are 1. The three inputs to each of the AND gates correspond to the three switches, sometimes directly and sometimes with the signal inverted by the three inverters directly under the switches. Recall that if the input to an inverter is 0, the output is 1, and if the input is 1, the output is 0.

The three switches at the top are shown closed, open, and open, which denotes the binary number 100. If you trace through the red lines, the most significant digit of 1 is one of the inputs to the AND gate associated with octal number 4. The next digit (the switch in the center) is inverted before it becomes an input to that same AND gate. The least significant digit (the switch at the right) is also inverted before it becomes the third input to that AND gate. Thus, the AND gate associated with the octal digit 4 has all three inputs set to 1, and that’s why the output is 1.

Similarly, each of the other seven AND gates has as input a different combination of the signals from the switches or the inverted signals.

This little device is called a 3-to-8 decoder. The name implies that a three-digit binary number is a code that represents one of eight possibilities.

Another circuit, called an 8-to-3 encoder, performs the opposite task. For this job, let’s create a different type of switch that allows selecting one of eight positions. In real life, you could make something like this switch with thumb tacks or nails and a piece of metal cut from a can:

Images

A circuit to show the three-digit binary number that corresponds to an octal number from 0 to 7.

Each of the binary digits at the bottom is displayed using a lightbulb driven by a four-input OR gate. The output of the OR gate is 1 if any of the four inputs is 1. When the switch at top selects the octal digit 6, the first and second OR gates have an input of 1, which sets the output of these OR gates to 1, showing the binary digits 110. Notice that the 0 position of the switch at the top left is not connected to anything. That’s because the octal number 0 is the binary number 000, so no lightbulb needs to be lit.

Sometime around 1947, the American mathematician John Wilder Tukey (1915–2000) realized that the phrase binary digit was likely to assume a much greater importance in the years ahead as computers became more prevalent. He decided to coin a new, shorter word to replace the unwieldy five syllables of binary digit. He considered bigit and binit but settled instead on the short, simple, elegant, and perfectly lovely word bit.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.238.71.155