Number Systems


     It's always kind of strange to try to talk about different number systems, because inevitably and invariably a phrase like "ten equals eight" will pop up somewhere along the line. Unfortunately, the names given to numbers are inexorably tied to the number system of choice, the decimal system. Therefore, it's best to review some gradeschool math, and point out some of the mechanics of it which are absorbed and then applied almost automatically. And that's fine. But then the brain freezes when it has to figure out E7 + 1C. The calculation is no different, really; it's just that the values have been divided up differently. Yet the focus here is not about calculations in other number systems, but rather just to introduce said systems, and conversions between them.

First, a note about the terms used:
Value is used to describe the counted measurement of something, and are written out in word form, rather than numerically. If you are carrying an apple in each hand, then you have two of them, rather than 2.

Digit is used to describe the actual numbers used in the various number systems, and are represented numerically. The number 19 has two digits: a 1 and a 9.

Number is used to describe the combination of digits, which represent some value. 537 and F1 are both numbers, but ones which use different sets of digits. Yet the two of them may end up representing the same value.

     So, consider the decimal system. The prefix dec- refers to the ten digits that are used to represent values: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Decimal can also be called a base-10 system. Consider the following: if you start counting up from 0, you eventually reach 9. This is the highest digit in the number system; no other character can represent anything greater. Except 10 of course, but neither 1 nor 0 are greater than 9, so how can this be? Why, via place values of course.

    1       6        3      7       9
   ____    ____    ____    ____    ____
   10^4    10^3    10^2    10^1    10^0
     That is sixteen thousand, three hundred seventy-nine written in decimal form, which conveniently comes out as 16,379. Note the numbers under each place value: each is ten raised to a power, and thus they are part of the base-10 number system. The 1 in the 10^4 place means that there is one group of 10^4, or one 10,000. Simple enough, as multiplying by ten tends to be. Then there is a 6 in the 10^3 place, which means there are six groups of 10^3, or 6,000. Three groups of 10^2, seven groups of 10^1, and 9 groups of 10^0 mean 300, 70, and 9, respectively. Thus, 16,379 can be written the long way as:

(1 * 10^4) + (6 * 10^3) + (3 * 10^2) + (7 * 10^1) + (9 * 10^0)
Or
(1 * 10000) + (6 * 1000) + (3 * 100) + (7 * 10) + (9 * 1)
Or
10,000 + 6,000 + 300 + 70 + 9

     Why, isn't that just multiplying each digit by the value of its place? Sure. In decimal it's done without even thinking, but the process is really no different in any other number system.

     At this exact moment in 2002, the United States is about 342 years old. No, not three hundred forty-two. That's two hundred twenty-six, written in octal. As the name implies, octal is a base-8 number system that contains the digits 0, 1, 2, 3, 4, 5, 6, and 7 (that's eight digits total).
    3       4       2
   ___     ___     ___
   8^2     8^1     8^0
     Following the same process as before, this can be written as:

(3 * 8^2) + (4 * 8^1) + (2 * 8^0)
Or
(3 * 64) + (4 * 8) + (2 * 1)
Or
192 + 32 + 2
Or
226

     Unfortunately, just to add a little confusion, those calculations aren't octal calculations at all. They're decimal calculations. After all, there is no 8 in the octal system. But then, nor is there any "10" in the decimal system per se, yet that's what the system is based on: one digit higher than the highest one available. This is because that's how the place values are divided up. You can have your digits of 0 through 9 (for decimal) or 0 through 7 (for octal) or whatever, but the next value up can't be represented by a single digit. Rather, you simply add one to the next place value. In decimal, 9 + 1 is no problem. You get ten. Groups of ten are represented by the next place value. You have one such group. Drop the zero and carry the one. You get the number 10. Why should it be any more difficult in octal? 7 + 1 is eight. The next place value up represents a value of eight, so drop the zero and carry the one. You get the number 10.

     Therefore, the number "10" represents ten in a base-10 number system, eight in a base-8 number system, sixteen in a base-16 number system, or fifty-seven thousand, six hundred ninety-three in a base-57693 number system (I will call that one "DVal").

     Such is the method behind all these systems. But now there's another problem. You only learned ten digits in school, and now suddenly you have to represent fifty-seven thousand, six hundred ninety-two of them before you finally make it to the number 10. Well forget it. There's absolutely no way anyone is going to choose to memorize fifty thousand digits over nine. It looks like DVal is dead before it ever got to experience the joys of life. That's alright, though, because hexadecimal lives on, and it does manage to represent values greater than nine using a single digit, and with a reasonable number of said digits.

     Hexadecimal (hex meaning six and dec meaning ten, for a total of sixteen) consists of the following digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. So A in hexadecimal (hex for short) is equivalent to 10 in decimal. A is ten. 10 is ten. 12 is also ten, but let's not go there yet. F means fifteen, the greatest valued digit possible in a system based on sixteen (just as 9 is the largest in a system based on ten, or as ~, which is a digit I have just made up to represent fifty-seven thousand, six hundred ninety-two in DVal, is the largest in a system based on fifty-seven thousand, six hundred ninety-three).

     I can sit here all day and make up numbers to base one of these systems on, but that would be completely pointless. Come to think of it, what's the point of using any of these systems, when decimal is easier, and it's what you already know? Why, there is none, unless you're working with computers. Oh, and speaking of computers, there's one last number system to learn, and this one is really, really important.

     That's right, I'm talking about binary. It's scrolling by in the Flash banner at the top of this page. More importantly, it's scrolling by in the bowels of your computer's microprocessor. More specifically, in the form of two different levels of voltage, it's passing through millions upon millions of logic gates. Boolean logic gates. The binary system is implemented in computers through Boolean logic, but that's another issue. For now, we are concerned only with the number system itself.

     Bi. Two. There are only two digits available in binary: 0 and 1. As of the year 2002, the United States is 11100010 years old.
     1     1     1     0     0     0     1     0
    ___   ___   ___   ___   ___   ___   ___   ___
    2^7   2^6   2^5   2^4   2^3   2^2   2^1   2^0
Rather: (1 * 2^7) + (1 * 2^6) + (1 * 2^5) + (0 * 2^4) + (0 * 2^3) + (0 * 2^2) + (1 * 2^1) + (0 * 2^0)
Or
(1 * 128) + (1 * 64) + (1 * 32) + (0 * 16) + (0 * 8) + (0 * 4) + (1 * 2) + (0 * 1)
Or
128 + 64 + 32 + 0 + 0 + 0 + 2
Or
226

     What do you know? It's no different from the other number systems, except that it takes eight of these binary digits (bits) to represent the same value that can be shown with only a 3-digit decimal number, and because we describe these values using words based on decimal, 226 is a whole lot easier to read than 11100010, even though both of them are "two hundred twenty-six." On the plus side, computers work with eight-bit segments called bytes, so you'll never have to work with a binary number greater than 11111111 (two hundred fifty-five).

     By the way, you can come back groveling to octal and hex after you shunned them before. They can be used to represent in three or two digits (respectively) what binary needs eight digits to show. This means nothing to the computer, which can calculate those bits faster than any technician or engineer can convert them to something intelligible, but it means plenty to said technician or engineer. Binary 11111111 is just as easy to remember as hex FF, but what about 01001101? 00010110? Therefore, the next step is to know how to convert between these number systems.

The method used before to explain the significance of place values is, in fact, a method of conversion. It can be used to convert a number of any base system to decimal.
     3     1
    ___   ___         =   (3 * 8^1) + (1 * 8^0) = 24 + 1 = 25
    8^1   8^0

     F     3
    ____  ____        =   (15 * 16^1) + (3 * 16^0) = 240 + 3 = 243
    16^1  16^0

     1     0     1
    ___   ___   ___   =   (1 * 2^2) + (0 * 2^1) + (1 * 2^0) = 4 + 0 + 1 = 5
    2^2   2^1   2^0
     That's all well and good, but often times decimal isn't used to display binary. Internet addresses use decimal, of course: 192.168.63.138, for example. In many other situations, hex or octal is used instead. The reason why these two are used, and not, say, a base-42 system, is due to their common base factors.

     Base-2, base-8, and base-16. Notice anything? Two is a factor of eight (2 * 4), and eight is a factor of sixteen (2 * 8). Here are the binary place values again, presented in decimal form:

    ___   ___   ___   ___   ___   ___   ___   ___
    128    64    32    16     8     4     2     1
     Octal counts up to 7 before carrying over to the next place, right? Four plus two plus one equals seven, right? Those are the values of the first three binary places (counting from the right), right? Perfect. One octal digit can represent those three places, no problem.
                                    |
    ___   ___   ___   ___   ___     |    ___
    128    64    32    16     8     |    8^0
     So, 8^0 ca represent a maximum value of seven (7 * 8^0). 8^1, then, can represent a maximum of fifty-six (7 * 8^1). Fifty-six, as in 32 + 16 + 8.
                   |                |
    ___   ___      |       ___      |    ___
    128    64      |       8^1      |    8^0
     Well, there are two places left, not three, but that's alright because they have high values. Next up is the 8^2 place. This allows for a maximum value of 448 (7 * 8^2). That's much, much larger than we would need to represent a binary number no greater than 255. Still, there are two binary places left over, so we'll just have to use only part of the third octal place.

     We can reason this one out. We're into groups of 8^2, so for each 1 here we have a value of sixty-four. 128 + 64 is 192. 64 + 64 + 64 is also 192. To finish up those last two binary places we need a third octal place, but it can hold a value no greater than 3 (3 * 8^2 = 192) if we're representing only eight bits. Therefore, the range of octal values should be 000 to 377, right? Let's check it out. 3778 should equal 111111112, which is 25510. Yes, the subscript after each number indicates which base system is used.

     3778 is equal to a 7 in the 8^0 place, plus a 7 in the 8^1 place, plus a 3 in the 8^2 place.
     This is equal to: (3 * 64) + (7 * 8) + (7 * 1)
     This is equal to: 192 + 56 + 7
     This is equal to: 255

     Yep, it works out. Converting from binary to octal or vice versa is very simple.

     For binary to octal, you first break the binary number into segments of three bits each (starting from the right).
     11000101 would become: 11 000 101
     Note the two bits on the far left. If it were forced into a group of three, the empty space would be assumed to be 0, since it wouldn't change the value of the number any. This is why you have to start from the right. If you break up the bits starting from the left, you end up with the two bits on the right. You can't add any 0s on that end: it would change the value of the number.

     Moving on, you simply convert each set of three bits into an octal number. It isn't very difficult. With only three bits to work with, the greatest octal value you can have is seven. The 11 on the left converts to an octal 3. Here's why.
     0     1     1
    ___   ___   ___
    2^2   2^1   2^0
     2^1 is 2, and 2^0 is 1. Multiply each by one, then add them together to get three. Note the imaginary 0 tacked on to the left. In an eight-bit number, that doesn't really exist, but for these calculations it doesn't matter because it has no effect on the value of the number. And yes, those place values are not actually equal to 2^1 and 2^0. They equal 2^6 and 2^5 in the binary number, but for the conversion it doesn't matter at all. There's certainly a clear and precise mathematical reason for it, but unfortunately I'm no math major, so just remembering the three-bit segments will do. Don't take my word for it though: try it out and see.

     Repeat the process for the next set of bits. 000? That's simple. An octal 0.
     Lastly, there's the 101. A one in the fours place plus a one in the ones place equals 5: an octal 5. All together, the octal equivalent of 110001012 is 3058. Convert to decimal if you'd like to know what it "really" is.
(3 * 8^3) + (0) + (5 * 8^0) = 3 * 64 + 5 = 192 + 5 = 197

     Great. 110001012, 3058, and 19710 all represent the same value, which we describe as "one hundred ninety-seven." Except now it isn't so bad to hear such a thing, because I've conveniently added the subscripts to them, and because the concept of different number systems should hopefully be clear by now.

     Conversion from octal into binary is not much different. Just work in reverse to convert 3, 0, and 5 into three-bit binary, then string them together.
3 is 011, 0 is 000, and 5 is 101.
     Strung together yields a binary number of 11000101 (that extra 0 was dropped from the final answer). Is that what we started with? Good.

     Ah, but that leaves hexadecimal-binary conversions. Those don't have to be explained much, for they follow the same rationale as that used in octal-binary conversions. The far right four bits are values of 1, 2, 4, and 8, which add up to 15. Values up to fifteen can easily be represented by a hex digits 0 through F. The only difference now is that the binary number is to be broken up into segments of four bits, instead of three. This means that any eight-digit binary number can be represented with only two hex digits. (A single hex digit represents four bits, or half a byte, and thus it is called a nibble; cute, huh?)

     Consider that same binary number from before: 11000101. This time convert to hexadecimal.
     11000101 becomes 1100 0101.
     The 1100 is equal to a hex C. Remember that digits after 9 are letters: A for ten, B for eleven, C for twelve, D for thirteen, E for fourteen, and F for fifteen. 1100 is twelve, and twelve is C, so 1100 is C. The 0101 becomes a 5. Therefore, 110001012 is equal to C516.

     And as for working in the reverse direction, simply convert each hex digit into four bits of binary, then combine them. Consider 1E.
     1 = 0001 (1), and E = 1110 (14)
     Therefore, 1E16 = 000111102.

     Since these are groups of four bits, it would be extremely useful to have the first four binary place values memorized: eight, four, two, and one, in that order from left to right. In a way, to convert from binary to hex, you first have to convert to decimal, in that you add together the decimal values of the bit places occupied by a "1," then convert that to a hex letter (A through F). 1001 is 8 + 1, which is 9. 1011 is 8 + 2 + 1, which is 11, which is a hex B.

     Speaking of decimal, there is one last conversion: from decimal to one of these other systems. This can be done by dividing the decimal by the value of some place in the other number system, and then proceeding as with normal long division. It works like this:

     What is 19810 in binary?
     Be familiar with the binary place values. With eight-bit numbers, the greatest place value is 128. Therefore, attempt to divide 198 by 128.
     Hey, it works. Once. That's how you know you're dividing by a large enough place value. Remember that you're working with binary. There can be only a 1 or a 0. If you get a 2 or more, you have gone horribly astray, and you'll have to try again, dividing by a larger place value.
        ___1     A 1 in the 128 place.
    128| 198
        -128
         ___
          70


        __1      A 1 in the 64 place.
     64| 70
        -64
         __
          6


        __0      There's no way 32 is going into 6. A 0 in the 32 place.
     32|  6


        __0      16 is still too big to go into 6. A 0 in the 16 place.
     16|  6


        __0      Nope. A 0 in the 8 place.
      8|  6


        __1      Finally: a 1 in the 4 place.
      4|  6
         -4
         __
          2


        __1      A perfect fit. A 1 in the 2 place, and a 0 in all remaining places.
      2|  2
         -2
         __
          0

     1     1     0     0     0     1     1     0
    ___   ___   ___   ___   ___   ___   ___   ___   = 11000110
    128    64    32    16    8     4     2     1
     That's converting into binary. To convert to hexadecimal or octal or DVal, the process is exactly the same, except that you divide by the place value of those respective systems rather than the 128, 64, 32, and so on of binary.

     Rather than map out that whole process again, here's 198 into hexadecimal: 198 / 16 = 12, with a remainder of 6. 6 / 1 = 6. 12 is C. 19810 = C616.

     There. Had enough? I have. Do enough of these and it'll be second nature, just as easy as working with decimal. That way you won't have to depend on the Windows calculator or some other device, which I conveniently neglected to mention.


Back to the Main Page

1