For many who have learned all their life about base 10, (10 fingers we have) it is sometimes hard to understand how to count with bianry and hexadecimal. I hope to help out where I can in this matter.
For starters, as many of us started out in school, we were tought how to count based upon how many fingers we have. This is the common way to count for many aspects of life ex: money, time, temprature, age, or any form of measurement.
Decimal:
There are some fundamentaly basic rules to how we count that we all were tought as well as to how it all works.
These are: when dealing with base 10 or decimal (same thing).we use 10 digits from 0 to 9
0 1 2 3 4 5 6 7 8 9
We also have place holders starting with the ones place, tens, hundreds, thousands, ten thousands, hundred thousands, and soforth
In order: Hundred Thousands | Ten Thousands | Thousands | Hundreds | Tens | Ones
When we count, we start at the ones place and work our way up. Always remember that the placeholders are always there but when there are no digits in the placeholders, it is implied that that placeholder is a zero.
So, with the ones place we start with 0 then 1 and all the way up to 9. But 9 is the last digit so we must start again but we also need to keep track of how many times we have gone through the cycle from 0 to 9. This is where the tens place comes in. After the 9 cycles back to 0 we place a 1 in the tens place and start the cycle from 0 to 9 all over again. When the second time through is complete, the tens place changes from a 1 to a 2 and soforth.
Once the tens place reaches a 9 itself we must then keep track of how many times we went through the tens place. After a 9 here and a 9 in the ones place we have 99 then the Hundreds place takes charge and becomes a 1 with both the Tens place and the Ones place starting back at 0's again. Which lead us to 100.
This is nothing new and you may feel I am being a idiot for taking everyone back to kindergarden with this but these rules are the same for all other counting bases.
Bianary:
With Binary, we only have 2 digits being 0 and 1
And likewise with decimal having 10 digits, the placeholders are based on multiples of this.
In decimal we satarted with the Ones place and jumped to the tens place because of the fact there are 10 digits to work with. Since there are only 2 digits with bianary, we need to follow a similar scheme.
The first place is the same as with decimal, The One place ( notice I said One and not Ones)
So lets start counting right away. 0 is 0 is 0. Nothing is diffrent here as is a 1 in the one place, but after this there is nomore and we must start over again. But like before we must keep track of how many times we have cycled through it so we have to put a 1 next to it and start the one place over at 0. This new place holder is the two place. This would look like 10. Since there is a 1 in the two place and 0 (nothing, zilch, nota) in the one place then we have the number 2 in bianary.
Well since the one place is a 0 we can count up to a 1 with it now so lets do it.
11
We now have a 1 in the two place and a 1 in the one place. What is 2 + 1 = ... 3
Well now. We now have 1 and 1 which can no longer go any higher so we need a new placeholder. This next one is the four place. And the next instance in our sequence woud be 100. With a 1 occupying the four place and nothing in the two or one place we obviously have '4' !
Yay. Isn't bianary counting fun?
If you can see a trend here it is that the place holders double in value as you go to the next one when viewing it as a decimal number. SO the next placeholder will be 8. We now have (in order) 8 4 2 1
And like before if we count only the placeholders with 1's occupying them, we have the bianary number in decimal. easy as that.
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
~~~~~
1111 15
On a side note, when working with computers and dealing with the bianary that goes with them, we break down the information with terms that group certain amounts of digits together. A single solitary digit in bianary is a BIT.
On a lesser used term these days, when 4 bits are grouped together it is known as a nibble ane when 2 nibbles are grouped together you have a byte. As all of you know.
Hexadecimal:
Hex is actualy the easiest once you have gone though bianary. Reason being is that bianary and Hex (as is the way to call it for short) are so closely related that all computer these days use both bases to process data.
On another side note that really isn't prudent to this cause it never had a good purpose I guess, was the long forgotten Octal. This is just base 8 and serves nothing any longer as far as I know. I would love for someone who know what this base was used for to step in and discribe it here.
Now to Hex. Hex is known as base 16. However since normal decimal counting only goes as high as 9, new digits needed to be created or just use something we already have. This is where letters came into place when counting.
A B C D E F
which corespond in decimal to 10 11 12 13 14 15
Because of this counting method, Bianary values relate DIRECTLY to HEX.
With a byte we have 2 groups of 4 bits which when counted in bianary by themselves go as high as 15 in decimal. Hence one Hex digit. So we then have a high nibble and a low nibble. And if both of them are 15 then both are F. When they are read together we have FF which is viewed as 1111 1111 in bianary and as 255 in decimal.
In conclusion I hope this help some who may be struggling with understanding how these diffrent bases correspond to each other. I also hope I have not just been a skiping record where many others have done this before. If so, just take it for what it is worth.
As a bonus I will give a breif example of how to convert decimal to bianary by using subtraction.
First you need a decimal number. 87 This one will do.
Then check you placeholders in bianary 1 2 4 8 16 32 64 128 ... Well 128 is too high to accomodate this number so we will start with 64.
Subtract 64 from 87 and we have 23
Now 32 being the next one down will not subtract from 23 so we skip it by placing a zero in that placeholder. The next is 16. Now 16 will subtract from 23 and we then have 7
8 won't work so 0 for that one
4 will and that leaves us with 3
2 works with 1 remainding
and take away the last one with 1
There! Now place ones one each of the placeholders that you could subtract and zeros where you couldn't. You have
1010111
If we wrote this as a full byte it would be 01010111. And converting to HEX would be taking 0101 0111 and we would have 57 which is our HEX value.
Awesome stuff huh? Anyway happy coding!
Edited by grafixbmp, Mon Nov 24, 2008 11:14 PM.














