Convert a denery number into any base-n
To me, this is the hardest part of converting between bases: from decimal to a different base. However, don't let my math conundrums confound you. The process is very simple and without pitfalls, if not a bit circuitous. We'll try one to get a feel for the process because the process is the same for every base, which is a good thing we don't have to remember a bunch of conversion rules. To prove this point subtly, I'll start off converting a denery number into an odd base, base-7.
Convert 15810 into base7
I. The first step is to take the target base to varying powers and attempt to divide it into the source number to get the largest part.
II. Subtract the product of the multiplication from the dividend of the division. This sounds overly complicated. Put another way, 158 - 147 = 11. We're subtracting (the number of times 72 goes into 158 * 72) from the original base-10 number, or our starting number.
I'll complete the step here.
That is our base-7 number: 15810 = 3147
Convert denery into binary
What is 15810 in base-2? We can figure that out now that we have our rules in place. I'll go through it short form, but not an entirely terse fashion. You will need, however, to recall binary value placement. I'll add up the digits into the binary value at the end.
Notice I didn't move any numbers into the target base locations this time. In binary, we'll either have it going into a number one or zero times. Look back at the calculations as I add the numbers.
128 + 16 + 8 + 4 + 2
128 64 32 16 8 4 2 1 1 0 0 1 1 1 1 0
So the decimal number 15810 is 100111102.
Convert decimal into hexadecimal
Ready to try your hand at converting decimal to hexadecimal? Good, I thought so.
What is 15810 in base-16? First, let's use some intuition. How many digits should the hexadecimal number be? Two, right? The number 158 is less than FF, which is 255.
For converting from decimal to hexadecimal there is a different way that I learned and prefer and I am going to show it to you now. It is much easier -- in my opinion -- that what you've just done thus far.
The general heuristic is divide by 16, multiple remainder by 16, convert to hex.
158 / 16 = 9.875
Take the remainder (.875) and multiply it by 16 and round up if necessary.
.875 * 16 = 14.
This is the digits place and 14 in hexadecimal is E: 0xXE
Take the number without the remainder from the previous step, which is 9 and divide by 16, but since 9/16 = 0, move the nine over: 0x9E
The number 15810 is 9E16, 0x9E or 9Eh hexadecimal. Isn't that much easier?
Convert denery into octal
Because we've covered that odd base-7 earlier, and it's just a bit of the same thing with using eights instead of sevens I'll leave this section as an exercise for the reader. Convert 15810 into base-8.