The first step to understanding bases is figure out what base a number is part of. To do that, count how many numbers are in that number's number system.
- Binary only has 2 characters in it: 0 and 1. Thus, binary is referred to as being a base 2 number system.
- Our Decimal system has 10 characters in it: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Thus, our decimal system is referred to as being in base 10.
- Hexadecimal has 16 characters in it: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. Thus, hexadecimal is a base 16 number system.
If a number is not written in base 10 (Decimal), it should have a subscript saying what base it is in. Example: Binary should be written like this: 1010101011101002
Do you remember how they taught you to add in grammar (elementary for Americans like me) school? You used columns like the ones, tens, hundreds, thousands, etc. column. Like when you had a problem like the one below:
19
+3
-----
22
You were taught to add a one to the tens column after you exceeded the value of nine in the ones column. (You were also taught to add a one to the hundreds column after you exceeded a value of 9 in the tens column and so on and so forth). If you had for example, a 2 in the the ten;s column wit would have a value of 10 because 10*2=20. Likewise, that 9 in the example above has a value of 9 because 9*1=9. I guess you could say Number*ColumnValue=TrueValue. Most importantly, what I'm trying to do here is jog your memory of that 'columns system'.
Now consider this: How do you think the value of each column was determined?
The value of each column was determined by taking the base number (10 in our decimal system) and giving it an exponent of the column placement. Remember you move from right to left when doing this. Thus, the first column was the ones column because 10^0 is 1. The second column the tens column because 10^1 is 10. The third column the hundreds column because 10^2 is 100.
Now this column system I've finished fully describing applies to any base, just change the base number. So for binary (base 2), the first column is the one's column because 2^0 is 1. The second column is the two's column because 2^1 is 2. The third column is the four's column because 2^2 is 4. The fourth column is the eight's column because 2^3 is 8.
11112 (binary) is equivalent to 15 in decimal because (1*1)+(1*2)+(1*4)+(1*8)=15.
For hexadecimal (base 16) this application works the same way. The only thing that throws some people off about hexadecimal is the letters. Here's the hexadecimal to decimal conversion for them:
Hex -> Decimal A 10 B 11 C 12 D 13 E 14 F 15Before I move on with my lesson I want to point something out quick that's in huge relevance to digital circuitry and programming. The max value for one character of hex is 15. Thus, any one character in hex is equivalent to 4 characters in binary. If you don't fully understand why, take a look at that 1111 in base 2 equals 15 in base 10 example above again. Each binary character is actually called a bit in technological vernacular and each hex character is called a nibble. Two hex characters next to each other (AB for example) is called a byte.
So now, finally, let's calculate the decimal value of a hexadecimal (base 16) number:
A35D16
First let's figure out the column values (Remember, we're working from right to left):
16^0 is 1 so the first column on the right is the one's column. The column next to it on the left is then the sixteens column. Then the two-hundred-fifty-six's column. Lastly on the far left we have the four-thousand-ninety-six's column.
So let's add it up:
(10*4096)+(3*256)+(5*16)+(13*1)=41821
If you understand all of this, you should now be able to count in any base be it base 2 binary, base 16 hex, or base 398 (whatever that's called). If not, read over the tutorial. I've truly made this as short and sweet as possible. Good luck :-)
If you have any questions regarding the content of this post, feel free to leave a comment, join me in #arikadosblog on EFNET, post in our forums, tweet to me, or send me an e-mail at castlevania7689@yahoo.com.
No comments:
Post a Comment