Numbering Systems: Back
to William's Archives.
Here is a little essay I have excerpted from our book. The title
of thebook is, "The Anatomy of a PC". The book is a
step by step, photo illustrated guide to building your own computer
from components.
When I was just a boy, I went to school and the teachers taught me how to count. Then they taught me to add, subtract, multiply and divide numbers. They taught me the decimal numbering system. Base ten. They did not tell me that the system I was learning was merely a set of conventions. They taught it as law! That's the way it was.
That was many years ago. Now-a-days, I'm told, youngsters in our local schools are taught the decimal, the binary, and sometimes even the octal system. Young folks, with very flexible minds, have little trouble with these concepts. It doesn't bother them at all that the decimal system is only a convention and not a divine concept.
Unlike these modern children, I had a great deal of trouble with the alternative numbering systems when I first encountered them. I was learning to be an electronic technician at the time and here I was, confronted with a different way of counting. It was quite traumatic coming to terms with the fact that my revered teachers had mislead me. In retrospect, I can see that it was nothing more than ignorance on their parts and not diabolical at all. They would not have known binary from Shinola. They had no reason to.
With some effort, I overcame my conditioning and learned a different way of thinking about numbers and arithmetic. I learned well enough that I believe I can explain binary arithmetic for those who don't know and want to. As always, it's best to start with something we know. Then we can notice what's different. I'll start with a short review of our conventional decimal system.
Let's start with a single number equal to zero.
0
Now we can add the number 1 to it. The zero becomes a 1.
1
If we add another 1 the 1 becomes a 2.
2
If we continue to add 1 to our number it will eventually become
9. Nine is our largest possible digit in the decimal system.
9
Now we will add another 1. What happens when we do?
The 9 becomes zero and a 1 appears to the left of our number.
That is, in the tens column.
10
In computer jargon, that's called a left shift. In human language,
it's called a carry. If we continued, we can see how we could
have a hundreds column, a thousands column, and so on! We understand
that the first column has a weight of 1 for each digit, the second
column has a weight of 10 for each digit, the third column has
a weight of 100 for each digit, and so on. Notice that the weight
is multiplied by 10 for each left shift. That's because our base
is ten.
Back in school, starting with these simple concepts, we learned to add, subtract, multiply, and divide. We learned to do arithmetic in the decimal numbering system. Base ten.
Now, here's the good news. The binary system, base two, works
exactly the same way. The rules still apply. The only difference
is that, in binary, the largest possible digit is 1 (one) instead
of 9 (nine). That is the only difference. So let us take a single
number equal to zero.
0
If we add 1 to the zero it becomes 1. Our largest possible digit.
1
Now, we will add another 1. What happens when we do?
The 1 becomes a zero and a 1 appears to the left of our number.
That is in the twos column. In computer jargon, that's still called
a left shift. In human, it's still called a carry.
10
Now, if we add another 1, what happens? The same thing that would
happen in decimal arithmetic. We will get a 1 in the ones column.
Like this.
11
Now, the next time we add a 1, we will get another left shift
from the ones column which will also cause a left shift in the
twos column. Like this.
100
We end up with a 1 in the fours column. If we continued, you will
see that we could have an eights column, a sixteens column, and
so on. We understand that the first column in binary arithmetic
has a weight of 1 for each digit, the second column has a weight
of 2 for each digit, the third column has a weight of 4, and so
on. Notice that the weight is multiplied by 2 for every left shift.
That's because our base is two.
How does that apply to our computer? If we had an eight column
binary number we could represent it with a single computer byte.
For review, a bit is the computer's smallest particle of information.
It can have a value of 1 or 0 (on or off). A byte is eight bits
of information with each bit being either on or off (1 or 0).
If we think of each bit in our byte as having a weight based on
it's position, the weights would be:
128, 64, 32, 16, 8, 4, 2, 1
If you add these weights, you will get 255. Thus, we can represent
any number between 0 and 255 in a single computer byte. How would
we represent decimal 27 in a binary byte?
Like this: 00011011
Add the weights of the set (on) bits. 16 + 8 + 2 + 1 = 27
This is how we represent numbers in a computer. Isn't that swell?
I can hear you saying, "Yeah, but!"
255 ain't much of a number. What happens if we want to add 1 to
255? Would you believe a left shift into the next, leftmost, byte.
In regular binary arithmetic, that is what we would do. To represent
number between 0 and 65,535 we would use two bytes. Work it out.
Just double the number for every left shift. Are we limited to
two bytes to represent numbers? Of course not. We can use as many
bytes as we need.
In addition, there are other ways of representing and dealing with numbers in computers. We can actually represent complex numbers of any form. And, to be sure, we can also have signed numbers. The fantastic part is, we do it all with 0's and 1's. 0's and 1's are all we have in a digital computer.
I hope, by now, you will realize that it is all a matter of
convention. Decimal arithmetic, which we normally use, is just
one convention. Binary is used extensively in digital computer
work. Two other numbering systems, which are sometimes used in
the computer world are octal, base eight, and hexadecimal, base
sixteen. How would those work out? Use the example above and think
it through. For digits over 9 in hexadecimal, use symbols. For
instance, use A to represent 9 plus 1. The revelation should be
that any base and numbering system is possible. Even a variable
base system like Roman numerals. It is just convention, not law!
Back to William's Archives.
|
|
|
|