Non-Decimal Numbering

{ If you have any comments or questions regarding this tutorial, please E-mail me }

This is acutally a supplement to the ASM Tutorial on this site, however, it can be beneficial to anybody who desires to know more about binary/hex/octal, etc.
Firstly, to understand another form of numbering (called a "base"), we need to obtain a better understanding our standard numbering system - Decimal.
Let's take a look at a random decimal number:
892 - read "eight hundred ninety-two".
Okay, so how does it differ from similar numbers such as:

This may seem trivial, but the point here is that you can form different numbers using the same digits. A digit is bigger or smaller depending on its position in the number (what order the digits are in).
Going back to 892, let's break it down into its digits and what value they get because of how they're positioned:
8 - represents 800, or 8 follwed by 2 zeros, because it's 3 spaces from the right.
9 - represents 90, or 9 followed by 1 zero, because it's 2 spaces from the right.
2 - represents 2, or 2 followed by 0 zeros, because it's 1 spaces from the right.

So, we could conclude that as a digit moves to the left, it's multiplied by larger multiples of 10. First it's multiplied by 1, then 10, then 100, then 1000, then 10000, and so on. Once you multiply each digit by the proper multiple of 10, you add them together:
8 * 100 = 800
9 * 10 = 90
2 * 1 = 2
800 + 90 + 2 = 892

But 1 doesn't seem like a multiple of 10... Maybe, then, multiple is a bad word for it. We should call 1 a power of 10.
Recall that anything to the power of 0 is 1.
1, then, is 10^0 (meaning ten to the power of zero; ^ is the exponent symbol when dealing with computers, because you don't always have the option of using superscripts like so: 100)

As you probably learned early on, you can call each "column" by a name - The ones column, the tens column,....... the hundred quadrillions column, and so on. But, as we established, each column should more accurately be described as a "Ten to the [some number] power" column. This starts with the 10^0 column on the right - the first column - and increases to the 10^1 column, 10^2 column, and so on, for however many digits you have.

So, how does this apply to other numbering systems? It turns out that different numbering systems differ in how big a digit can go in each column. Binary, for example, is commonly described as "ones and zeros". It's just that - it uses only 2 digits instead of 10. Binary is also known as "Base-2", because it's based on two digits. Decimal, then, is called "Base-10", because it's based on 10 digits.

Well, how else are other numbering systems different? In decimal we multiply each number by 10 to the power of its column number (digit * 10ColumnNumber), then add our results together. If it's 10 for decimal, which is base-10, it must be 2 for binary, right? Yes.

So, with this in mind, let's look at binary.
We've established that it's just like decimal, but it only uses 2 digits, and you get the overall value of the number by multiplying by powers of 2 (since it's base-2) instead of 10.
Here's some examples of decimal numbers and their respective binary representations
[decimal number first - binary second]

 0 00000000 1 00000001 2 00000010 3 00000011 4 00000100 5 00000101 6 00000110 7 00000111 8 00001000 9 00001001 10 00001010

the leading zeros are just there to show the 1s as the move up the columns.
Just like in decimal, when you try to add to an already "maxed-out" column, you add to the next column instead, and make the maxed out column equal 0.
Let's walk through that table above, in case it's not completely clear.
In the first row of the table, we have 0. With binary, as in decimal, 0 is 0.
Now, add 1 to that: In both decimal in binary 1 is 1. No trick here. Now, add 1.
In decimal, it's just 2. However, in binary, 2 is not a valid digit. We can only use the digits 0 and 1. Therefore, the first column is full - it contains 1. If we try to add to that, we must follow the rule that we move to the next column, and make this one equal 0. So, in binary, 2 is 10. It's important to not read 10 binary as "ten". Read it to yourself as "one oh".
Now, add 1 to that. The decimal value is 3. In binary it's 11. We try to fill the rightmost column if it's not already full....
Hopefully, If I explained it at least okay, you're getting it. Let's break down a few increasingly large binary numbers and find out what what they equal in decimal.

1110b (the 'b' means 'binary')

Let's use the rule of powers... The rightmost column is called "column 0 (or 2 to the power of 0)", the next one "column 1 (or 2 to the power of 1)", and so on.. Simply take each digit and multiply it by 2 to the appropriate power:
0 * 2^0 = 0 * 1 = 0
1 * 2^1 = 1 * 2 = 2
1 * 2^2 = 1 * 4 = 4
1 * 2^3 = 1 * 8 = 8
8 + 4 + 2 + 0 = 14
And, if you're not convinced, you can check that on a calculator that can do base conversions.

Our next number to try:
11011001b

1 * 2^0 = 1 * 1 = 1
0 * 2^1 = 0 * 2 = 0
0 * 2^2 = 0 * 4 = 0
1 * 2^3 = 1* 8 = 8
1 * 2^4 = 1 * 16 = 16
0 * 2^5 = 1 * 32 = 0
1 * 2^6 = 0 * 64 = 64
1 * 2^7 = 1 * 128 = 128

1 + 0 + 0 + 8 + 16 + 0 + 64 + 128 = 217
That should cover it. For further, clarification, let's look at hexidecimal

Firstly, the prefix HEX on a word means "6", and the prefix DEC means 10 (like decimal as mentioned ealier). If decimal is base-10, and binary (bi meaning "2") then Hexi + Deci + mal must be base-16.
We know that the base refers to how many possible digits per column exist. hexidecimal has 16 digits. But, how are those written? 0-9 only constitutes 10 digits, which works fine for binary and decimal. In the case of hex, and everything above base-10, you use letters when you run out of numbers.
Here are the digits used in hex and their decimal value:
0 through 9 = 0 through 9
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15

Following the same rules as binary and decimal, and any number base for that matter, we take the value of each digit and multiply it by 16^columnNumber (in the case of base-16).
Some examples

10h (the 'h' means 'hex' - it's not a digit)
0 * 16^0 = 0 * 1 = 0
1 * 16^1 = 1 * 16 = 16
0 + 16 = 16

F9h
9 * 16^0 = 9 * 1 = 9
F * 16^1= 15 * 16 = 240
9 + 240 = 249

A6Eh
E * 16^0 = 14* 1 = 14
6 * 16^1 = 6 * 16 = 96
A * 16^2 = 10 * 256 = 2560
14 + 96 + 2560 = 2670

After all this, we can say something in general about conversion from any base to decimal.
Given a number represented in base basenum, with columns labeled 0 starting at the right and increasing by 1 with each successive leftward column, the decimal value equals:
The sum of the value of each digit raised to the power of basenum.

Originally posted at http://www.doorknobsoft.com/