Another document I trawled up from my college days. Its a Beuty



This is the very first tutorial that I have ever published and I want you to send every single comment you have and every single thought you think, while reading this, to my email address written near the end of this file. I have divided this into two chapters. Chapter one explaining what you have to know, before you can make your own conclusions and methods. The second is a short one just to finish off with what you probably wanted to learn by reading my tutorial. The first chapter is the most important, and you shouldn't skim past anything you don't quite understand.
I promise that when you have read this file, and thought about the things in here, you will have an indept knowledge of how the complex numeral systems work. If you want more than that, I suggest that you, after reading, make a list of numbers and values and then convert them to everything you can think of.
Just remember that, practice makes perfect.
-snider

Chapter 1: Basic Bases

What is a base? A base is what defines all the different numbering systems. It defines how many different digits, a numbering system has. To start, the decimal system has 10 different numbers (0-1-2-3-4-5-6-7-8-9, (count them for yourself)) and is therefore base 10. Now the big question arises, what to do when you hit 9 and want to add one more? Well, a lot of heads smarter then ours put together the simple method of pushing the digits around a bit. 10 was the result, which is actually built from 1 tens and 0 ones. 15 is 1 ten and 5 ones. Because the decimal system is base 10, it also means that it works on the basis of the power of 10. The third column in the decimal systems is therefore 100's. I will try to explain.


BASE 10 (decimal)

column 7 6 5 4 3 2 1
power 1000000 100000 10000 1000 100(hundreds) 10(tens) 1(ones)

This is the chart I will be using in the rest of this tutorial, and it is important you understand this. From here you can simply read that the seventh column digit represent how many times there are 1000000's in a number. The number 65000000 will have 5 times in the 7 column and 6 in column number 8 (NOT 65 times in the seventh column). Since we write numbers with the most powerful first, I have chosen to set the columns up in the same way, with the first column, far left.

But this is all very natural as we were taught math in school, when we were only seven. Since we have lived with that ever since, it is hard to imagine how it would be if we didn't have a numbering system with base 10.


The next step in the understanding of the numbering systems is to grasp that the number 250 in decimal isn't a number, but instead a code for a number. Just like another code for that number is 11111010 and also 372. Lets take the number 15 again. 15 consists of 1 ten and 5 ones. Now this is in base 10:



***** *****
***** |
| |
one ten |
and five ones.
Lets take the octal system. It is base 8 (0-1-2-3-4-5-6-7). Now (decimal)15 is:


**** ****
**** ***
| |
one eight |
and seven ones
You see, it's still (decimal)15 asterisks, but now it is also (and has always been)


17
/ \
one eight \
and seven ones
The chart for base 8 is (as you probably could figure out for yourself by now)

BASE 8 (octal)

column: 7 6 5 4 3 2 1
power: 262144 32768 4096 512 64 8 1 (values in decimal)

AND

column: 7 6 5 4 3 2 1
power: 1000000 100000 10000 1000 100 10 1 (values in octal)

(This last chart is pretty abstract, so don't feel stupid if you don't quite understand it.)

Got everything so far? Lets make some more conversions. Lets take (decimal)435 to base 7.

BASE 7

column: 7 6 5 4 3 2 1
power: 117649 16807 2401 343 49 7 1 (in decimal values)

Now, do we have anything in column 7? Lets try, 435 divided by 117646 won't do. What about column 6, 435 divided by 16807.. No. It is obvious that the first digit is in the fourth column. So 435 divided by 343 is 1 and with a remainder of 92. Now we know our final number in base 7 will be 1---, and that we still have 92 to convert. So 92 divided by 49(column 3) returns 1 with a remainder of 43. Now we have 11-- and 43 to convert to base 7. 43 divided by 7 is 6 and the remainder of 1. Now we have 116- and the remainder of one. The rest is very easy to figure out as _n_ divided by 1 always will return _n_. So our final base 7 number is 1161. And don't think there are some times when it doesn't work out because of some weird numbers, it will always work out since nothing but the format of the value changes.
In short, the value is still (decimal)435. Now it is simply not displayed using 5 _ones_, 3 _tens_ and 4 _hundreds_, but using 1 _ones_, 6 _sevens_, 1 _forty-nines_ and 1 _three-hundred-and-threes_. Now try to pronounce the number (base 7)1161. One-thousand-one-hundred-sixty-one? No, that would be pronouncing it in decimal. It should be pronounced one-one-six-one-seven (the last seven telling that it is base 7).

Ok? Well so far so good. Lets go on with the how and why of base 5.

BASE 5

column: 7 6 5 4 3 2 1
power: 15625 3125 625 125 25 5 1 (decimal values again

The first column always have to indicate the lowest natural value possible, that's one. The second column is the base^1, in this case 5. The third column, base^2, in this case
5^2 = 5 * 5 = 25
Fourth column is then base^3
5^3 = 5 * 5 * 5 = 125
And so on...
So here's your final mathematical formula:

B^(C - 1) = column C's power.

C = column
B = base

That is the end to Chapter 1: Basic Bases.

Chapter 2: What you really wanted to learn, Hex and Binary

Welcome to the second chapter. Here we will attack the two number systems Hexadecimal and Binary.

Lets start with the easy one: Binary...

The binary numeral system is the longest way to write any value. Whatever value you choose to convert to binary, it will always be more digits than your original number. That is because binary is base 2. Only two numbers can be displayed, 0 or 1. Yes or No. True or False. Power or No power. The heart of any computer system (for now). With the formula in the last chapter we can figure out how to convert a base 2 system to base 10 numbers.

BASE 2 (binary)

column: 9 8 7 6 5 4 3 2 1
power: 256 128 64 32 16 8 4 2 1
If you can understand my charts by now you can see that the 2 base system is very simple. But also very hard to read for humans. The number (decimal)23 would be one 16 value, one 4 value, one 2 value and one 1 value.
That's 10111!

As I said, very hard to read for human beings.

This is why Hexadecimal was invented (yes and I do mean _invented_). Hex is a base 16 system, and therefore it is very advanced, but still easier to read than binary. And extremely easy to convert to and from binary because of some simple logical rules. Lets begin.
The Hex system is as I said base 16 and for that reason, new numbers had to exist. The 'numbers' became A-F (0-1-2-3-4-5-6-7-8-9-A-B-C-D-E-F). F is the highest number, representing (decimal)15 alone. The chart for hex would look like this:

BASE 16 (hexadecimal)

column: 8 7 6 5 4 3 2 1
power: 268435456 16777216 1048576 65536 4096 256 16 1

(The power is still displayed in decimal)

I will leave it to you to get comfortable with converting from decimal to hex and vice versa. Now, converting from binary to hex and the other way around is simple. Lets look at them both.

Do you see how hex jumps from one to sixteen in one column and how binary jumps from one to sixteen in four columns? This is the breaking point of the story. For every four binary digits they represent the value of one hex digit. Why? Well, because


(remember the formula?)

2^(5-1) = 16
and
16^(2-1) = 16

16 = 16
(in short: they can represent the same number of values)

So, when you want to convert binary to hex you part the number in four columns each.
(decimal)155 = (binary)10011011

part it, and calculate a little..


1001 1011
| |
9 B
final...

(decimal)155 = (hex)9B
Note: hex is written either [number]h or 0x[number], so (hex)9B is either 9Bh or 0x9B.

The trick always works. (Actually it's not a trick but a logical, mathematical functionality :P)

This is the end of Chapter 2.


All comments, improvements, hashes, asterisks and keypresses can be sent to blacksuns text-update group, if desired ofcourse.

Thanks for reading..