Updated Tuesday, March Eighth Two Thousand and Five in the Year of our Lord.
|
This document is meant for beginners. I tried to simplify it as much as I could, and I hope it helps people out. Feedback is, as always, greatly
appreciated! E-mail nekom@dark-logic.com .
We are all familiar with our decimal number system. We have ten digits, 0 through 9. This is what we call a base 10 number system. It is really
arbitrary that we wound up using a base 10 number system, but it probably has something to do with the fact that we have 10 fingers. We were
all taught the decimal number system since our early days of education. Most of us were not, however, even introduced to other number
systems, and many of us aren't even aware of them. This is not a problem for the most part, until you begin to deal with the inner workings of
the computer.
Why are binary, hexadecimal and octal important in the world of computers? Well, at the lowest level, every piece of data a computer handles
is stored in binary. Be it data on a compact disc, your hard disk drive, RAM, a diskette, or whathaveyou, the media is simply a series of 'ON'
and 'OFF' bits; on being 1 and off being 0. 8 of these bits comprise a byte. So that explains the need for understanding binary, but why
hexadecimal and octal? Well, a 'byte' (8 Binary digits) can be expressed as two hexadecimal digits, or as three octal digits. Though the use of
octal has faded in popularity of late, hexadecimal is still widely used. Many binary file editors use hexadecimal to express each byte. They even
go so far as to call them 'hex editors'. Hexadecimal numbers are also widely used in programming. In a C++ program for instance, you can
directly enter a hexadecimal number (for instance the base 16 number 0F3A is entered as 0x0F3A). Furthermore many technical documents,
such as interrupt lists, heavily rely on the hexadecimal number system. As this document will illustrate, it's not that hard working with binary,
hexadecimal, octal, or any other number system.
Every number system, be it decimal (base 10; what most of us are familiar with), hexadecimal (base 16), octal (base 8), or Binary (base 2),
follows the same basic format. In any number system, you have a number of digits, and each digit has a magnitude, based on the number
system's base, raised to the power of the digit.
- Let's use an example we'll all understand, the decimal number 917.
You will notice that this number has three digits. The magnitude of these digits, running from right to left, are based on that number's base (10 in
this case) raised to the power of that digit's position, the rightmost digit being at position 0, and the leftmost in this case being at position 2.
Let's begin with the first digit, that is the one on the right. We call this the least significant digit. It's value is 7. 10 to the power of 0 is 1. In fact,
any positive integer to the power of 0 is 1. Therefore, no matter what number base we are working with, the least significant digit's significance
is 1. Now to get the real value of this digit, we must multiply it by 1. It's still 7, of course, which means that the rightmost digit simply represents
a value of 7. Simple enough, right?
Now let's move on to the next digit. This one is a 1. And 10 (our base, remember?) to the first power is equal to 10. SO this digit's value is 10
* 1, or 10. Now when we add that to our previous digit, we get 10 + 7, or 17. Now we only have one more digit to work with.
The final digit is a 9, and it is the 3rd digit (or digit number two, since we begin the count at zero) The digit is a 9. 10 to the 2nd power is 100. 9
* 100 = 900. So we add that to our 17 and get 917, the value of the number. Piece of cake!
OK, SO WHAT??? The value is 917, I could have told you that just by looking at it! Well, I'm sure you could have (if you couldn't, you have
no business reading this document!) But could you look at 01110110 (as a binary number) and tell me what the decimal value of that is? All
you have to do is follow roughly the same procedure. The only thing that changes is the base. We use base 2, or binary. Let's break that down
and see if it works out, using the example number of 01110110.
Another way to think of this number is:
No ones, one two, one four, no eights, one sixteen, one thirty-two,
one sixty-four, and no one hundred twenty-eights.
In the same way, the above example of the decimal number 917 can be thought of as seven ones, one ten, and 9 hundreds.
Now you see how this can come in handy!! Now that you have a rundown of binary, you could probably figure out hexadecimal and octal, as
long as you know that they are base 16 (hex) and 8 (octal). But I'm going to demonstrate nonetheless.
Let's have a look at octal. Let's use an example number of 257 in octal. We'll use the same chart to break this number down as we did above.
Remember that in octal, our base is 8.
And finally, hexadecimal, or base 16. But first, we have to consider that we cannot represent a base 16 number using our 10 digits. So we must
use letters as digits. 0 through 9 have the same decimal value as they would otherwise, but in hexadecimal, the letters A through F must also be
used. A represents 10, B represents 11, C represents 12, D represents 13, E represents 14, and F represents 15. Let's have a look at the
hexadecimal number 2F8
There are other number systems out there, but they are not extremely common in the computer world (or any world for that matter). I did read
once about an ancient culture that used a base 20 system. There are theoretically an infinite amount of number systems, and the methods
described above will work with them all. I hope you've found this document useful.
This document is (C)Copyright 2005 Dark Logic. This document may be freely linked to, or redistributed without profit in its whole form, with proper credit due.