If you can add two more characters to your set to make it good even 64, then there is a simple, fast algorithm that I can describe here.
Encode numbers in a three- or four-bit code as follows:
0: 000 1: 001 2: 010 3: 011 4: 100 5: 101 6: 1100 7: 1101 8: 1110 9: 1111
This is a prefix code, which means you can look at the first three bits to see if you need to use the fourth. If the first three bits as an integer are greater than 5, then get one more bit. Thus, decoding will:
get three bits as n if n < 6 the result is n + '0' else n = (n << 1) + one more bit the result is n - 6 + '0'
Then the bit is simply stored six at a time in one of 64 valid characters.
This has a problem if you do not know a priori how many digits there are, since there will be ambiguity if you leave four or five bits not used in the last character. In this case, the code can be changed simply like this:
0: 000 1: 001 2: 010 3: 011 4: 100 5: 1010 6: 1011 7: 1100 8: 1101 9: 1110 eom: 1111
which takes a few more bits, but provides a unique marker for the end of the message.
In the first example, you will store an average of 1.76 digits per character. For the second example, 1.71 digits per character, less than some value for the eom marker, depending on the number of digits that you encode at a time.
If you really can use only 62 characters, then I will need to think about this a bit.
Update:
A quick look at RFC 1738 indicates that a lot more characters can be used in a URL:
lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" hialpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" alpha = lowalpha | hialpha digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" safe = "$" | "-" | "_" | "." | "+" extra = "!" | "*" | "'" | "(" | ")" | "," unreserved = alpha | digit | safe | extra
Thus, adding, say, $ and _ to your set will make it 64.