Chapter 2: Numbering Systems

 

Notes

 

Introduction

Before moving on to explain how a computer stores information (such as instructions, or your program’s source files), I must explain numbers and numbering systems.  I must warn you that this can be a confusing topic to many people and a great hurdle that must be leapt over.  The concepts covered in this chapter must be understood if you are to understand programming.  Only extremely basic math skills are required; you only need to be able to add and subtract.  If you feel stumped and this chapter does not help you, I encourage you to write me so we can work out what it is that is blocking you from understanding.

 

What is a number?  Ever since you learned to think for yourself you’ve been pummeled with these things called numbers.  In school you’re forced to learn how to write them, add them, and do any number of torturous tasks with them.  Later in life you’ll use them to balance your checkbook or see how much in debt you are.  But what are they?  A number in is simply a representation of a value or count.  You can represent a numeric value using one of many numbering systems.  These systems define how a value is represented, obviously.  Two that you may know of already are decimal and Roman Numerals.  But then there are others with no names.  If I held up two fingers I would be representing a count or amount of two fingers which is the same as the number 2.  As you can see, I can write in long-hand, hold up fingers, write numbers, or use any number (pun pun) of ways to communicate a numeric value.  It might be thought of, then, as a universal language.  You’ll even note that numbers everywhere seem to be represented the same (in decimal) even though words are completely different.

 

Most of our numeric abilities are automatic ever since elementary school.  You see 6 and you can automatically discern that it represents an amount of six or six things:

 

Six       =          J         J         J         J         J         J

 

Regardless of how six is represented, the value still stays the same.  In decimal we represent this as ‘6’, long-hand as ‘six’, and Roman Numerals ‘VI’.  They all look differently, but mean the same thing.  This is an important thing to remember.  How you display a numeric value does not change the amount it represents.

 

The Decimal Numbering System

 

Decimal is a very logical system for representing numeric values and as such it has spawned many other numbering systems, for good or ill.  Because of this I will first try to explain how decimal actually works.

 

The decimal numbering system uses Arabic numerals.  A numeral is a character or glyph that represents a single numeric amount.  The Arabic numerals are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.  The amounts they represent are below:

 

0          =          <nothing>

1          =          J

2          =          JJ

3          =          JJJ

4          =          JJJJ

5          =          JJJJJ

6          =          JJJJJJ

7          =          JJJJJJJ

8          =          JJJJJJJJ

9          =          JJJJJJJJJ

 

A decimal number is comprised of one or more of these numerals strung together.  Each column’s numeral is known as a digit.  A decimal digit can, then, only be one of these ten different numerals and so multiple digits are needed to represent values greater than the largest of these numerals (nine).

 

In the case of multiple digits, the value is produced by adding the values of each digit together.  However, there is a catch.  Each digit’s value is its numeral amount (as shown previously) multiplied by its weight.  A digit’s weight is ten to the power of the digit’s column position.  The right-most digit is in position zero (0).  The next digit, to the left, is in position one (1) and so forth.  The first digit is always the right-most and the last is the left-most.  In the decimal number 1234, the positions are as so:

 

            Decimal Digit:   1                      2                      3                      4

            Position:           3                      2                      1                      0

 

So then the weight of each of these digits would be:

 

            Weight: 103                   102                   101                   100

 

And therefore each digit’s value would be calculated as such:

 

            Calculation:       (1*103)                        (2*102)                        (3*101)                        (4*100)

 

So the value of each digit would be:

 

            Value:               1000                200                  30                    4

 

Add them together (1000 + 200 + 30 + 4) and you get 1234 or “one thousand, two hundred thirty-four”.  Now, you already know this because you’ve used decimal all your life.  And I bet you’ve taken it and this process completely for granted.

 

Bases Loaded

 

Decimal sure does use a lot of “ten” doesn’t it?  Yes!  Decimal is known as “base ten”!  The base of a logical numbering system like decimal determines the following:

 

 

Other numbering systems I will be describing follow all the same rules, but they have a different base.  In these numbering systems zero is counted.  Each digit then can hold as many values as the base of the numbering system.  Decimal is base ten and therefore can hold one of ten values in each digit.  This is because, again, zero is counted.  A digit in decimal can hold one of its ten Arabic numerals and therefore represent one of ten different values.  However, the maximum amount of each is always one less than the base (nine in the case of decimal).

 

The Fivemal System

 

To explore this generic use of system base (not “boom boom boom” bass, dammit!), let’s create an imaginary numbering system that is base five called Fivemal.  I’m choosing this amount because it is half of ten and therefore might be pretty easy to understand.  Because it’s base five, the weight of each digit will be five to the power of the digit’s position.  All numbers written in Fivemal will have ‘(f)’ appended to them so you can see which ones are not Decimal.  For my first demonstration I will represent the value three (JJJ) in Fivemal:

 

            3(f)

 

Wow, that was exceedingly painless.  It still looks the same and only uses one digit because we have not equaled or exceeded our base which is five (JJJJJ).  What happens if we do?  What if we want to show the value six (JJJJJJ)?  It would like look the following in Fivemal:

 

            11(f)

 

Woh, wait a minute!  That looks like eleven doesn’t it?  In decimal that would be eleven, but that’s because decimal is base ten.  Our own numbering system, Fivemal, is only base five.  The value six, then, must use two digits.  Each digit’s weight in Fivemal will be a multiple of five.  Simply “knowing” the numbers doesn’t help much now does it?  Now you have to figure out the value of the number by actually using the rules I tried to explain earlier.  Let’s break it down.  First we’ll look at the weight of each digit:

 

            Fivemal Digit:    1                      1

            Weight: 51                     50

 

Since the digit’s value is its numeral amount multiplied by it’s weight, the calculation for each digit’s value would be:

 

            Calculation:       (1*51)              (1*50)

 

Added together this would be 6 in decimal.  Please remember that ‘6’ in decimal is simply a way of representing the same value (JJJJJJ) written as ‘11(f)’ in Fivemal.  Fortunately, any time we are converting from a foreign system like Fivemal, all numbers used in the calculation are typically written in decimal.  The only one not written in decimal is the one whose digits are being converted.  Let’s look at the conversion to decimal from Fivemal from the top:

 

            11(f) =

            (1*51) + (1*50) =

            5 + 1 =

            6 (JJJJJJ)

 

Notice that the only number in this whole process that isn’t decimal is the ’11(f)’ at the top.  This process can be used to convert a number from an abstract base to decimal, or base ten.  It can also be used to split up a decimal number as we saw earlier, but then it’s yield will always be that same decimal number.  For example, let’s break down one hundred thirty-five in decimal using this process (and I’m not going to placate you by putting down that many smileys!):

 

            135 =

            (1*102) + (3*101) + (5*100) =

            100 + 30 + 5 =

            130 + 5 =

            135 (many smileys would go here …)

 

Distinguishing Numbering Systems

 

You need to know what numbering system a number is using to be able to use it effectively.  But how do you know what system a number is in?  Most systems add something to the display of the number in order to convey the system.  In Fivemal I added ‘(f)’ to the end of the number to show that it was represented “in Fivemal”.  Decimal is the only one that doesn’t.  This means that if there are no distinguishing marks on the number (strange spacing, leading/ending characters, etc.) then it is most definitely a decimal number.  For the numbering systems I will be describing I will also show you how they are written so they can be distinguished from decimal and their counterparts.

 

Converting Between Systems

 

You’ve already actually learned how to convert from any based system to decimal.  But how to do you convert from any based system to another abstract base system or even from decimal to another based system?  This is where it starts to get difficult.

 

To be done here:

 

The Binary System (base 2)

 

This is the simplest system of all because its base is the lowest you can go.  Yup, that’s right.  There is none lower.  Base one can’t possibly exist because each digit would have to be zero and therefore the highest number a base one system could represent would be zero (nada, nothing, zilch).  In base two, as it is, each digit can only be either 1 or 0.  For example, the number 5 in binary is:

 

            0101b

 

First let me explain how binary is distinguished from other systems in writing.  First off, the number of digits will almost always be a multiple of four.  If that many digits are not required, the number is padded with zeroes.  Secondly, any one of the following things may be used, so if you see any one of these on a number, it is probably written in binary:

 

·        Every four digits (to the left) there is a space.

·        The number ends with a ‘b’ or ‘B’.

·        The number begins with a percent sign ‘%’ (don’t ask me … I never use that one).

 

Now, let’s look at some numbers written in binary.  In fact, let’s go back to our value five (JJJJJ) in binary:

 

            Binary Digits:    0                      1                      0                      1

            Weight: 23                    22                    21                    20

            Value:               (0*23)              (1*22)              (0*21)              (1*20)

            Calculation:       0 +                   4

 

Side Note: Because each digit represents a power of two, the binary numbering system is also called “two’s complement”.

The Hexadecimal System (base 16)

 

Blaha

 

The Dead System (Octal, base 8)

 

Blah