09-26-2013, 04:41 PM
(This post was last modified: 12-15-2013, 11:50 PM by Neogreenyew.)
Prerequisite for this tutorial is the knowledge of binary and binary arithmetic.
INFO: You won't learn anything from this post unless you have the will to learn.
Hexadecimal is base 16.
Binary is base 2, so the only numbers allowed are 0 and 1. In hexadecimal we can use the numbers 0-9 and the letters A-F.
First things first, let's get in the habit of writing binary values by grouping everything together into sets of 4.
For example:
0000000000000000 is equal to
0000 0000 0000 0000
Note that the 0's are grouped into sets of 4 now.
Back to the values of hexadecimal values. Below is a chart of the hexidecimal value (top) and the corresponding decimal value (bottom)
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Pretty simple, eh?
Well now on to converting values from hexadecimal to decimal. There are 2 ways we can do this. We can either do it the extremely hard way, or the easy way. Which would you choose?
Let's first convert the decimal number 13 into hex. What is the corresponding value from the chart above?
That's right, it's D. So 13 in dec. = D in hex.
How about something larger than 15... let's convert 50 this time.
First let's convert this to binary.
50 in binary is equal to 32+16+2, which is 00110010.
Notice that I wrote that as an 8bit value; this is important.
Remember how we write our binary values as sets of 4? Let's do that to our result for the binary value of 50.
0011 0010
Let's integrate this into hexidecimal now. If we have a binary value of 1111 (the max value for that set of 4), we have the number 15. In hex, the decimal value of 15 is equal to F. So 1111 = F. This is why we write our binary values in sets of 4.
So to find the hexidecimal value of our number, all we have to do is convert each of the sets of 4 separately.
0011 = 3(decimal) = 3(hexidecimal)
0010 = 2(decimal) = 2(hexidecimal)
So our hexidecimal value is 3 2. Notice that I added a space between the 3 and the 2; this helps avoid errors such as if we had the values 1 and 2 next to each other. We wouldn't want to mix up the values 1 and 2 with the value of 12, would we?
So 50 in decimal is equal to 3 2 in hexidecimal.
Do this conversion on your own.
Convert the decimal value 122 into hex.
ANSWER:
122 dec. = 0111 1010 bin. = 7 A hex.
Now let's convert a hex value into decimal.
We have two ways to do this. We can either choose the easy way or the extremely annoying way. Which one would you like to do?
Of course you'd choose the annoying way, who wouldn't?!
Let's start off by converting the hex value of A F F 4 9 C 2 into binary.
A = 1010, F = 1111, F = 1111, 4 = 0100, 9 = 1001, C = 1100, 2 = 0010
Now put them all together.
1010 1111 1111 0100 1001 1100 0010
And convert that into decimal using the traditional method that you should already know by now.
"But wait! That's super annoying and long, there must be a better way."
You're right, there is! There is a simple function that we can use in order to simplify an annoying process like that.
Start off by converting any letters into their binary value.
That gives us 10 15 15 4 9 12 2
Now let's use two different functions.
The first is to multiply the value of each index by 16 raised to the index and add them all together.
(10 x 16^6)+(15 x 16^5)+(15 x 16^4)+(4 x 16^3)+(9 x 16^2)+(12 x 16^1)+(2 x 16^0)
Feel free to do this on a calculator.
After adding all of this up, your answer is 184502722.
Now there's another function (that I figured out all on my own )
Multiply the number by 2^(4*index)
Here's what it looks like.
10(2^(4*6))+ 15(2^(4*5)) and so on...
Now this function can be simplified by just raising 2 to the previous index +4. I'll use 'n' to signify a random value in the next example
n(2^24)+n(2^20)+n(2^16)+n(2^12)+n(2^8)+n(2^4)+n(2^0)
Notice that the number that 2 is being raised to is counting up by 4 from the right to the left.
If you want to learn how to multiply hex values together, go ask someone else because I'm lazy (as you could probably tell by the lack of grammar in this post) and I don't feel like doing it right now.
Here's a helpful video that can teach you hex as well. Check out this guy's channel for more tips on binary and hex and even some coding.
http://www.youtube.com/watch?v=m1JtWKuTLR0
And here's the wiki page
http://en.wikipedia.org/wiki/Hexadecimal
INFO: You won't learn anything from this post unless you have the will to learn.
Hexadecimal is base 16.
Binary is base 2, so the only numbers allowed are 0 and 1. In hexadecimal we can use the numbers 0-9 and the letters A-F.
First things first, let's get in the habit of writing binary values by grouping everything together into sets of 4.
For example:
0000000000000000 is equal to
0000 0000 0000 0000
Note that the 0's are grouped into sets of 4 now.
Back to the values of hexadecimal values. Below is a chart of the hexidecimal value (top) and the corresponding decimal value (bottom)
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Pretty simple, eh?
Well now on to converting values from hexadecimal to decimal. There are 2 ways we can do this. We can either do it the extremely hard way, or the easy way. Which would you choose?
Let's first convert the decimal number 13 into hex. What is the corresponding value from the chart above?
That's right, it's D. So 13 in dec. = D in hex.
How about something larger than 15... let's convert 50 this time.
First let's convert this to binary.
50 in binary is equal to 32+16+2, which is 00110010.
Notice that I wrote that as an 8bit value; this is important.
Remember how we write our binary values as sets of 4? Let's do that to our result for the binary value of 50.
0011 0010
Let's integrate this into hexidecimal now. If we have a binary value of 1111 (the max value for that set of 4), we have the number 15. In hex, the decimal value of 15 is equal to F. So 1111 = F. This is why we write our binary values in sets of 4.
So to find the hexidecimal value of our number, all we have to do is convert each of the sets of 4 separately.
0011 = 3(decimal) = 3(hexidecimal)
0010 = 2(decimal) = 2(hexidecimal)
So our hexidecimal value is 3 2. Notice that I added a space between the 3 and the 2; this helps avoid errors such as if we had the values 1 and 2 next to each other. We wouldn't want to mix up the values 1 and 2 with the value of 12, would we?
So 50 in decimal is equal to 3 2 in hexidecimal.
Do this conversion on your own.
Convert the decimal value 122 into hex.
ANSWER:
122 dec. = 0111 1010 bin. = 7 A hex.
Now let's convert a hex value into decimal.
We have two ways to do this. We can either choose the easy way or the extremely annoying way. Which one would you like to do?
Of course you'd choose the annoying way, who wouldn't?!
Let's start off by converting the hex value of A F F 4 9 C 2 into binary.
A = 1010, F = 1111, F = 1111, 4 = 0100, 9 = 1001, C = 1100, 2 = 0010
Now put them all together.
1010 1111 1111 0100 1001 1100 0010
And convert that into decimal using the traditional method that you should already know by now.
"But wait! That's super annoying and long, there must be a better way."
You're right, there is! There is a simple function that we can use in order to simplify an annoying process like that.
Start off by converting any letters into their binary value.
That gives us 10 15 15 4 9 12 2
Now let's use two different functions.
The first is to multiply the value of each index by 16 raised to the index and add them all together.
(10 x 16^6)+(15 x 16^5)+(15 x 16^4)+(4 x 16^3)+(9 x 16^2)+(12 x 16^1)+(2 x 16^0)
Feel free to do this on a calculator.
After adding all of this up, your answer is 184502722.
Now there's another function (that I figured out all on my own )
Multiply the number by 2^(4*index)
Here's what it looks like.
10(2^(4*6))+ 15(2^(4*5)) and so on...
Now this function can be simplified by just raising 2 to the previous index +4. I'll use 'n' to signify a random value in the next example
n(2^24)+n(2^20)+n(2^16)+n(2^12)+n(2^8)+n(2^4)+n(2^0)
Notice that the number that 2 is being raised to is counting up by 4 from the right to the left.
If you want to learn how to multiply hex values together, go ask someone else because I'm lazy (as you could probably tell by the lack of grammar in this post) and I don't feel like doing it right now.
Here's a helpful video that can teach you hex as well. Check out this guy's channel for more tips on binary and hex and even some coding.
http://www.youtube.com/watch?v=m1JtWKuTLR0
And here's the wiki page
http://en.wikipedia.org/wiki/Hexadecimal