A Brief Review of Bases

The base of a number tells us how many different symbols fit in a single digit. For example, people usually use base 10 with ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Base 2 is the base most often used by computers. It has only two symbols: 0 and 1.

Together, the digits of a number represent its value. Each digit represents a part of the whole number's value. For base 10 numbers, the rightmost digit is the ones digit, the next digit is the tens digit, the next is the hundreds (ten times ten) digit, and so forth. The same pattern holds in other bases.

As an example, let's figure out the value of 1011 in base two. The rightmost digit is the ones digit. The next one is the twos; the next is the fours (two times two); and, the leftmost one is the eights digit (two times two times two). So, the base 10 value of the number is 1 * 8 plus 0 * 4 plus 1 * 2 plus 1 * 1 or 11.

Bases greater than 10

To write a number in a base greater than 10, we need to have more than the ten symbols we normally use in base 10. No base 10 digit (0 through 9) will work for that! So, we use letters instead. As an example, base 16 is often used when discussing computers. In base 16 there are 16 possible symbols for each digit: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. The symbol A has the (base 10) value of 10. B's value is 11, C is 12, D is 13, E is 14, and F is 15.

Base 36 would have 36 symbols. The first ten are the base 10 digits. The next 26 are all 26 letters of the alphabet.

As an example, the number 230 in base 36 takes only two digits: a thirty-sixes place and a ones place. The number is 6E: 6 * 36 plus 14 * 1 (remember: E's value is 14).

Translating a base 36 number into base 10

You can translate a base 36 number into base 10 digit by digit. Let's say you have already translated the first two digits of a number: 6E with a value of 230 (as above). Now, you read another digit: A. A's value is 10. When you move 6E over by one digit to tack A onto the end, you need to multiply the number so far's value by the base (36). So, 6E times the base 10 value 36 (in base 36, that's 10!) is the base 36 number 6E0. When you add A's value to that, you'll get the base 36 number 6EA. To get 6EA's base 10 value, you can take 6E's base 10 value of 230, multiply it by 36 to get 8280, and add 10 to get 8290.

So, the algorithm is to multiply the base 10 value so far by the base (36 for us); then, add the base 10 value of the new digit. Repeat this step for each digit of a number, and you'll have found the base 10 value of the number.

Translating a single base 36 digit

You will need to read in digits of the base 36 numbers as characters. Therefore, you'll have to translate them into base 10 values. But, how do you get from the character '4' to the numerical value 4 or from the character 'D' to the numerical value 13?

Remember that we said you could translate characters to ints by casting them. Normally, this is not a very useful operation.. the integer value of a particular character is not very interesting. However, the difference between two characters can be quite interesting. For example:

  (int)'3' - (int)'0' == 3
The upshot of this is that you can translate a digit between '0' and '9' into a numerical value. How? Just subtract the integer value of '0' from the digit's integer value.

So, what about letter digits (like 'D')? Well:

  (int)'D' - (int)'A' == 3
How can you get the value of 13 from this? If you're not sure, notice that the following are also true:
  (int)'A' - (int)'A' == 0
  (int)'E' - (int)'A' == 4
Where A's base 10 value is 10 and E's is 14. Do you see a pattern?

That should be enough information to get you up and running with bases. Good luck!