Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [23]
We can continue counting on our four-toed feet:
When you're working with number systems other than decimal, you can avoid some confusion if you pronounce a number like 10 as one zero. Similarly, 13 is pronounced one three and 20 is pronounced two zero. To really avoid confusion, we can say two zero 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. And of course, the actual numbers refer to different quantities:
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.
When writing decimal and octal numbers, we can avoid confusion and denote which is which by using a subscript to indicate the numbering system. The subscript TEN means base ten or decimal, and EIGHT means base eight or octal.
Thus, the number of dwarfs that Snow White meets is 7TEN or 7EIGHT
The number of fingers that cartoon characters have is 8TEN or 10EIGHT
The number of symphonies that Beethoven wrote is 9TEN or 11EIGHT
The number of fingers that humans have is 10TEN or 12EIGHT
The number of months in a year is 12TEN or 14EIGHT
The number of days in a fortnight is 14TEN or 16EIGHT
The "sweet" birthday celebration is 16TEN or 20EIGHT
The number of hours in a day is 24TEN or 30EIGHT
The number of letters in the Latin alphabet is 26TEN or 32EIGHT
The number of fluid ounces in a quart is 32TEN or 40EIGHT
The number of cards in a deck is 52TEN or 64EIGHT
The number of squares on a chessboard is 64TEN or 100EIGHT
The most famous address on Sunset Strip is 77TEN or 115EIGHT
The number of yards in an American football field is 100TEN or 144EIGHT
The number of starting women singles players at Wimbledon is 128TEN or 200EIGHT
The number of square miles in Memphis is 256TEN or 400EIGHT
Notice that there are a few nice round octal numbers in this list, such as 100EIGHT and 200EIGHT and 400EIGHT. By the term nice round number we usually mean 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 100TEN, which is 10TEN times 10TEN. With octal numbers, two zeros on the end means that the number is a multiple of 100EIGHT, which is 10EIGHT times 10EIGHT (or 8TEN times 8TEN, which is 64TEN).
You might also notice that these nice round octal numbers 100EIGHT and 200EIGHT and 400EIGHT have the decimal equivalents 64TEN, 128TEN, and 256TEN, all of which are powers of two. This makes sense. The number 400EIGHT (for example) is 4EIGHT times 10EIGHT times 10EIGHT, all of which are powers of two. And anytime we multiply a power of two by a power of two, we get another power of two.
The following table shows some powers of two with the decimal and octal representations:
Power of
Two Decimal
Octal
2 0
1
1
2 1
2
2
2 2
4
4
2 3
8
10
2 4
16
20
2 5
32
40
2 6
64
100
2 7
128
200
2 8
256
400
2 9
512
1000
2 10
1024
2000
2 11
2048
4000
2 12
4096
10000
The nice round numbers in the rightmost column are a hint that number systems other than decimal might help in working with binary codes.
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:
Thus, an octal number such as 3725EIGHT can be broken down like so:
3725EIGHT = 3000EIGHT + 700EIGHT + 20EIGHT + 5EIGHT
This can be rewritten in any of several ways. Here's one way, using the powers of eight in their decimal forms:
3725EIGHT = 3 x 512TEN +