Base Conversion MethodOn this page we look at a method to convert whole numbers and decimals to another base. We give two examples of converting to base 26. This method will work for other bases, too.
Base Conversion of Whole Numbers
Base conversion of whole numbers is fairly easy if you use remainders.
Let's start with an example:
Convert 1208 to base 26
(base 26 is fun because it is the Alphabet)
For simplicity I will use A=1, B=2, etc, (in the style of spreadsheet columns) and use Z for zero, but another convention for base 26 is to use A=0, B=1, up to Z=25.
Watch this series of divisions (R means remainder, which is ignored in the next division):
|1208 / 26 = 46 R 12|
|46 / 26 = 1 R 20|
Now, think about the last answer (1 R 20), it means that 1208/26/26 = 1 (plus bits), in other words it tells us that we should put a "1" in the "262" column!!!
Next we should put a 20 in the "261" column, and lastly a 12 in the units.
Because our first division work has really said that:
1208 = 46 × 26 + 12
So, 12 belongs in the units column, and from here on we are dealing with the first power of 26:
46 = 1 × 26 + 20 (so 20 belongs in the ×26 column, and we put 1 in the ×26×26 column)
And if we substitute letters for numbers we get: ATL
Now, let's see if it has worked:
1 × 26² = 676
+20 × 26 = 520
+12 × 1 = 12
==> Total: 1208
So, to do whole numbers you do repeated divisions and put the results in from right to left
Note: if you use the A=0 style, then the code ATL is really B__ (you figure it out!)
What happens after the Decimal Point?
Now, if you have followed how to do whole numbers, we can look at "decimals" (hmmm... not an accurate word because it implies base 10 but you know what I mean).
To do "decimals", you use repeated multiplies and build from left to right.
Let us try an example using PI (3.1416...), and convert it to base 26. The whole number part is easy, it converts into base 26 as 3, so next we move on to the "decimal" part:
.1416 × 26 = 3.6816
.6816 × 26 = 17.7216
.7216 × 26 = 18.7616
Each time I drop the whole number part and just multiply the fractional part.
Now, the first answer says to put a 3 in the first "decimals" column, the second answer says to put a 17 in the second column etc ..
So the answer is:
And if we substitute letters for numbers we get: C.CQR
As a check I calculated 3 + 3/26 + 17/26² + 18/26³ = 3.141556..., and that looks pretty good!