On 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.
By "base" we mean how many numbers in a number system:
Base Conversion of Whole Numbers
Base conversion of whole numbers is fairly easy when we 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 ones.
Why?
Because our first division work has really said that:
1208 = 46 × 26 + 12
So, 12 belongs in the ones 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)
So the answer is:
262 | 261 | 1s |
1 | 20 | 12 |
And if we substitute letters for numbers we get: ATL
Now, let's see if it has worked:
1 × 262 = | 676 |
+ 20 × 26 = | 520 |
+ 12 × 1 = | 12 |
TOTAL: | 1208 |
So, to do whole numbers we do repeated divisions and put the results in from right to left
Note: if we 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 means Base 10 but you know what I am talking about).
To do "decimals", we 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
etc...
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:
3 | . | 3 | 17 | 18 | ... |
And if we substitute letters for numbers we get: C.CQR
As a check I calculated 3 + 3/26 + 17/262 + 18/263 = 3.141556..., and that looks pretty good!