Converting Bases

OK! Let's start. First of all, what is a number base? I really don't want to get into it, but there are a few other tutorials that might clear things up for you. Try looking at Binary 101 by Slax or The Binary, Octal and Hex System by Granpa.What I am going to tell you, however, is a simple way to convert from one base to another without having to remember or figure out what 16^5 is.

First of all I want to clear up one thing. For you who do not know, mod is the remainder when you do long division. Also I am going to refer to int as the integer that is rounded down or truncated. Also I usually use the European (I think) way of long division, which looks like this:

European way of long division
You can use the American way; it makes no difference, just that I find my way easier while converting bases.

OK. Now we are ready to start. First I'm going to explain how to convert from base 10 to any other base.


From Base 10 to Any Other Base

Let's say you have 1273 in base 10 and you want to convert it into base 7. What you do is you take 1273 and divide it by the base you are converting to, which in this case is 7. If you do the division correctly, you should get 181 for int and mod of 6. Ten you take int and divide it once again by the base. This time you get int 25, mod 6. Now you take your new mod and place it in front of the old one (you should have 66). Now you take the new int and once again divide it by the base. You should do so until int becomes smaller than the base. If you do the whole thing correctly you should get int 3, mod 4 for the third division. Once again take the new mod and place it in front of the old one (you should have 466). Now, since int is already smaller than the base, you take the int and place it in front of the mod (you should have 3466). Congratulations! You just converted 1273 in base 10 to base 7.

Here's a sketch of what I did:

Sketch of what I did
If you try to convert from 10 to any higher base, you might get a number greater than 9 for mod or last int. In this case you can substitute a letter or a symbol for that number. For instance is you convert 155 in base 10 to base 13, after first division you would get mod 12, int 11. Your answer would look like 1112, which could be easily confused with 1 1 1 2, while it is actually 11 12. This would make a huge difference. However if you substitute let's say B for 11 and C for 12, you would get BC. You do not have to use letters for numbers higher than 9, but it's a standard. If you decide not to use letters or use them in not alphabetical order, don't forget to include a key.


From Any Base to Base 10

Now I'll tell you how to convert from any number base to base 10. Basically what you are doing is reversing the method that I talked about above. Let's say you have 256 in base 6 and you want to convert it to base 10. First you take the first digit and multiply it by the base (2*6). What you should get is 12. Then you add the second digit to your answer and then multiply the sum by the base once again ((12+5)*6). You should get 102. Then you once again add the next digit to your answer, but this time, since it is the last digit, you do not multiply by the base (102+6). Your answer should be 108.


From Any Base to Any Other Base

To convert from any base to any other base, what you would have to do is basically combine the two methods together. First convert the number to base 10 and then convert the answer to a desired base.

I hope this made converting bases a little bit easier.

Thanks for reading.