Numbering Systems

Note: I have searched the tutorials forms and not found anything like this, If i'm stepping on anyones toes, or posting information already available neg me to death and i'll delete it. Anyways here you go. I had to do a numbering system tutorial for my fellow students, hopefully this will help ya'll out.

Decimal - The decimal numbering system is what we all know and use. It contains 10 digits (0 - 9) and then columns representing ones (10^0), tens(10^1), hundreds(10^2), thousands(10^3) and so on.

Binary - On and Off... A One or a Zero. This is the system that computers know and recognize. It contains 2 digits (0 - 1) and columns representing powers of 2. One (2^0), two ((2^1), four (2^2), 8 (2^3) and so on.

Octal - A number system using 8 digits (0 - 7). It is now considered to be somewhat archaic and is no longer used as much as it was in the past. The columns in octal represent powers of 8. One (8^0), 8 (8^1), 64(8^2) and so on.

Hex - A number system using 16 digtals (0 - 9 and A - F)... The letters represent the numbers 10 (A) - 15 (F). Hex is used all the time in the computer world. In MAC Addresses and Packet Captures, in programming, and in IPv6. The columns in hex represent powers of 16. One (16^0), 16 (16^1), 256 (16^2) and so on.

All number systems follow the same method to determine the number. You multiple the Value of the digit in the column by the value of the column

10 in decimal is 1 x 10^1 + 0 x 10^0

1010 in Binary is 1 x 2^3 + 0 x 2^2 + 1 x 2^1 + 0 x 2^0

12 in Octal is 1 x 8^1 + 2 X 8^0

A in Hex is 10 x 16^0

Now obviously the values that are 0 x ?? are not necessary, but even so, a big number can be a pain in the ass to convert. Conversion between binary and decimal is by far the easiest. With a binary number you can make a chart at first, but after a while the calculations can be done in your head.

To convert 10 (Decimal) to Binary. First write out the values of the binary columns (like below). Now work your way down the chart to the biggest number that goes into 10. The answer is 8, so put a 1 there. Fill in all spaces before the 1 with 0s. 10 - 8 = 2. So now find a number that will go into 2. 4 won't so the next one is 2.... put a 1 there and 0s in between. 2 -2 = 0.. you're done so put 0s in all the remaining spots

2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0

128 64 32 16 8 4 2 1

0 0 0 0 1 0 1 0

00001010 (you can drop all the leading 0s so your answer is 1010).

To convert the number back into decimal you would do the reverse process. Make the chart, and write the binary number in the columns. Then just add up all the column values where you put a 1.

How that we've done that.. let's look at converting octal and hex. The pattern for these two number systems is very similar.

The largest hex number is F which is 15 in decimal or 1111 in binary.

The largest octal number is 7 which is 7 in decimal or 111 in binary.

The pattern should seem obvious. Cut your Binary numbers into chunks. if you have the number 10101010 = 170 (decimal).

To conver to hex, cut it into 2 chunks of 4. 1010 and 1010. Here is a chart of how hex values compare to binary values.

0 - 0000

1 - 0001

2 - 0010

3 - 0011

4 - 0100

5 - 0101

6 - 0110

7 - 0111

8 - 1000

9 - 1001

A - 1010

B - 1011

C - 1100

D - 1101

E - 1110

F - 1111

So if we take our first chunk of 4 bits we see 1010 which on our chart is A, the second chunk is also 1010 so it is A again. So our hex solution is AA.

Hex numbers can also be converted backwards this way... say you had the number 3C. 3 in hex is 0011 in binary and C in hex is 1100 in binary. So your solution is 00111100, which if you convert it using your chart:

2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0

128 64 32 16 8 4 2 1

0 0 1 1 1 1 0 0

Add up the columns and you get 60 in decimal.

Now if we move to octal. Our chart is the first 8 digits of the hex chart:

0 - 000

1 - 001

2 - 010

3 - 011

4 - 100

5 - 101

6 - 110

7 - 111

If we work with the same number again, 10101010, for octal we break it into chunks of 3. We only have 8 digits so add an additional 0 to make it a mulitple of 3

010101010.. now we break that up and get 101 101 010

If we compare that to our chart, we get 2 for each chunk... or 252.

Again we can convert the octal back using this method... If we use 74.. We can break this up using the chunk method. We get 111 and 100, so the binary number 111100. We plug this into our chart and come up with

2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0

128 64 32 16 8 4 2 1

0 0 1 1 1 1 0 0

Add up the columns and you get 60 in decimal.

Now you should be able to easily convert numbers between any base. I hope you all find this somewhat useful.