First off, if you haven't read my first thread, here, I would suggest you do so. That is, unless you already are comfortable doing binary by hand.
I'm not going to do any numbers past 255 in decimal, or FF in hexadecimal, as this is just a basic tut, however if you pick up on this tutorial I would be willing to bet you would be able to figure out how to do it with larger numbers.
If you don't already know, hexadecimal is a base 16 number system. (hex = 6, decimal = 10) This means that instead of going to the next digit once you hit 9 (like in decimal) you go to the next digit when you hit "15" or F. Since we don't have single digit characters to represent 10-15, we use the letters A-F.
DECIMAL TO HEX
There are two ways to do this that I've found. One I liked when I was learning to do this, and one that I like now because I'm getting better at mental math. I'll start off with the one I find easier, which involves binary. If you haven't learned how to do binary, and don't want to, read below, otherwise go read my tutorial on binary here. For this part I'll be using hte example number 35.
METHOD ONE
STEP ONE
Convert your decimal number into binary. In this example, the number 35 is equal to the number 00100011.
STEP TWO
Mentally (or physically if you're doing it on paper) split your number in half.
Like so: 0010 | 0011
Think of the two groups as different binary numbers, one is 0010, and the other is 0011.
STEP THREE
Convert your two separate numbers back into decimal!
0010 = 2
0011 = 3
Now put those two numbers together, and you get 23! If you don't believe me, go check it on a hex/dec converter. I thought this was the easiest way to do it as it doesn't involve division, which is exactly what we'll be doing in the second quarter of the tutorial.
METHOD TWO
This one is a little bit more complicated, but I'm confident that if you've succeeded in comprehending my little binary trick, you'll be able to do this with little problem. (In your head that is)
Take the decimal number, in this case 172, and divide it by 16. The most important thing to remember is to LEAVE THE REMAINDER. If you don't, you have completely failed.
172 / 16 = 10 r12
Since in hex we have to confine the numbers into one digit, we'll call 10 "A" and 12 "C".
Kudos to those of you who have figured out exactly how this works with just the example above. Your first number is the first digit, and your remainder is your second digit. Therefore, 172 in hexadecimal is AC. Easy right? As long as you can do the larger numbers in your head, you'll be completely fine using this method.
HEXADECIMAL TO DECIMAL
This part is, in my opinion, the harder one. Though it's the same processes as before in reverse, it somehow manages to screw me up sometimes.
METHOD ONE
This is again going to use binary, so if you don't know how to convert between binary, I suggest you either skip to method two below, or learn how to do so in my thread here. In this method we'll be using the hexadecimal number F4.
STEP ONE
Convert your two digits into separate binary numbers. I like to keep them in four digits so that it makes more sense.
F is equal to 15 in decimal, so F = 1111 in binary. 4 = 0100
STEP TWO
Smash the numbers together into one eight digit binary number.
11110100
STEP THREE
Convert back into decimal! 11110100 = 244 Wasn't that easy? If you don't believe me check on either a binary/hex or a hex/decimal converter.
METHOD TWO
This one is hella easy if you have some pretty good mental math skills. Let's use the number 37 in hexadecimal for this example.
Take the first digit and multiply it by 16.
3 * 16 = 48
Now add the second digit to your number, 48 + 7 = 55. It's easy with a smaller number like this, but once you get past A it can get a bit confusing. At least it was for me for a while. Again, if you don't believe me check it out for yourself on a hex/dec converter.
I hop you enjoyed this tutorial, and I hope you learned something from it or have refreshed your memory. If you find a grammatical/spelling error please tell me about it. If you have any questions about this feel free to shoot me a PM. If you have any suggestions on making ths tutorial better by all means, post it. The same goes for suggestions on new tutorials. If people want an advanced tutorial (bigger numbers) I'd be happy to write it, but at the moment I'm being lazy and am going to stop here.
I'm not going to do any numbers past 255 in decimal, or FF in hexadecimal, as this is just a basic tut, however if you pick up on this tutorial I would be willing to bet you would be able to figure out how to do it with larger numbers.
If you don't already know, hexadecimal is a base 16 number system. (hex = 6, decimal = 10) This means that instead of going to the next digit once you hit 9 (like in decimal) you go to the next digit when you hit "15" or F. Since we don't have single digit characters to represent 10-15, we use the letters A-F.
DECIMAL TO HEX
There are two ways to do this that I've found. One I liked when I was learning to do this, and one that I like now because I'm getting better at mental math. I'll start off with the one I find easier, which involves binary. If you haven't learned how to do binary, and don't want to, read below, otherwise go read my tutorial on binary here. For this part I'll be using hte example number 35.
METHOD ONE
STEP ONE
Convert your decimal number into binary. In this example, the number 35 is equal to the number 00100011.
STEP TWO
Mentally (or physically if you're doing it on paper) split your number in half.
Like so: 0010 | 0011
Think of the two groups as different binary numbers, one is 0010, and the other is 0011.
STEP THREE
Convert your two separate numbers back into decimal!
0010 = 2
0011 = 3
Now put those two numbers together, and you get 23! If you don't believe me, go check it on a hex/dec converter. I thought this was the easiest way to do it as it doesn't involve division, which is exactly what we'll be doing in the second quarter of the tutorial.
METHOD TWO
This one is a little bit more complicated, but I'm confident that if you've succeeded in comprehending my little binary trick, you'll be able to do this with little problem. (In your head that is)
Take the decimal number, in this case 172, and divide it by 16. The most important thing to remember is to LEAVE THE REMAINDER. If you don't, you have completely failed.
172 / 16 = 10 r12
Since in hex we have to confine the numbers into one digit, we'll call 10 "A" and 12 "C".
Kudos to those of you who have figured out exactly how this works with just the example above. Your first number is the first digit, and your remainder is your second digit. Therefore, 172 in hexadecimal is AC. Easy right? As long as you can do the larger numbers in your head, you'll be completely fine using this method.
HEXADECIMAL TO DECIMAL
This part is, in my opinion, the harder one. Though it's the same processes as before in reverse, it somehow manages to screw me up sometimes.
METHOD ONE
This is again going to use binary, so if you don't know how to convert between binary, I suggest you either skip to method two below, or learn how to do so in my thread here. In this method we'll be using the hexadecimal number F4.
STEP ONE
Convert your two digits into separate binary numbers. I like to keep them in four digits so that it makes more sense.
F is equal to 15 in decimal, so F = 1111 in binary. 4 = 0100
STEP TWO
Smash the numbers together into one eight digit binary number.
11110100
STEP THREE
Convert back into decimal! 11110100 = 244 Wasn't that easy? If you don't believe me check on either a binary/hex or a hex/decimal converter.
METHOD TWO
This one is hella easy if you have some pretty good mental math skills. Let's use the number 37 in hexadecimal for this example.
Take the first digit and multiply it by 16.
3 * 16 = 48
Now add the second digit to your number, 48 + 7 = 55. It's easy with a smaller number like this, but once you get past A it can get a bit confusing. At least it was for me for a while. Again, if you don't believe me check it out for yourself on a hex/dec converter.
I hop you enjoyed this tutorial, and I hope you learned something from it or have refreshed your memory. If you find a grammatical/spelling error please tell me about it. If you have any questions about this feel free to shoot me a PM. If you have any suggestions on making ths tutorial better by all means, post it. The same goes for suggestions on new tutorials. If people want an advanced tutorial (bigger numbers) I'd be happy to write it, but at the moment I'm being lazy and am going to stop here.