We are so familiar with numbers from everyday use that it's easy to take them for granted. A mathematical view is useful for understanding numbers in computers.
When we talk about the numbers zero through twelve, a mathematician might conjure up an image like this.
The concept of number is tied to counting collections of things. The surrounding containers don't matter, just the collections.
This is the last of the rows above.
When we match the eggs in a carton or the donuts in a box one-for-one with the squares in ths group, we say they have the same number.
The concept of number is about quantity. It doesn't depend on names for the quantities. We call this particular number twelve or sometimes one dozen, but it has other names. The decimal expression \( 12 \) is just another name.
If you're careful with your laundry, when you look in your sock drawer, your socks are in pairs matching this collection that you know as two:
It is an accident of our biology that we use decimal numbers to name quantities. Our ancestors counted on their fingers long before it was discouraged in school.
Computers work best with binary numbers.
Electronic circuits can
quickly and reliably detect the presence of
voltage, which they associate with 1
,
or the absence of voltage, which signifies 0
.
Just zero and one. Back when computers
were huge and intimidating, people joked about
how stupid they were. No doubt, part of that was due
to this strange number system with just two digits.
From an early age, we hear about the ones place, the tens place, and so on. The very same concept applies to binary numbers. It just works a little slower. In binary, we have the ones place, the twos place, the fours place, the eights place, the sixteens place, the thirty-twos place, and so on, multiplying by \( 2 \) each time. We're out of breath before we reach the one-hundred-twenty-eights place.
But, wait, we're using our handy decimal numbers to talk about the binary world. Is that cheating? No, that's the point of the collections earlier. The number is what matters, not its name. We often use decimal language in human communication, even talking about binary arithmetic. But, when we talk to a computer in bytes, binary is best.
Let's look at the number \( 197 \). Somewhere along the way, we learned to decompose the number as \[ 197 = 100 + 9 \times 10 + 7 \] If we want to get fancy, we can emphasize the powers of \( 10 \): \[ 197 = 1 \times 10^{2} + 9 \times 10^{1} + 7 \times 10^{0} \] It all amounts to \( 197 \).
Using the byte odometer on the last page,
we can learn that \( 197 \) has the byte value
11000101
.
The breakdown into binary follows the pattern
of our familiar decimal numbers, but with powers of \( 2 \):
\[ 197 = 11000101_{2} = 128 + 64 + 4 + 1 =
2^{7} + 2^{6} + 2^{2} + 2^{0} \]
With practice, the powers of \( 2 \) become as familiar
as \( 1000 \), \( 100 \), and \( 10 \).
Returning to the dozen donuts we didn't eat earlier,
we see that our number 12 when stored in a byte
has the form 00001100
because
\( 12 = 8 + 4 \). It's another name for the same number.
Now let's do some byte arithmetic.