Possible Duplicate:
Integer to string with given radix
This question is inspired by Pythons builtin int
function. int
is used to convert other numbers or strings into integers. If you are converting a string you can provide the additional parameter base
, that contains the base that your number is represented in within the string:
>>> int('137')
137
>>> int('137',base=8)
95
>>> int('ff',base=16)
255
>>> int('1AZ',base=36)
1691
Unfortunately Python doesn't provide a function for the reverse case, where you want to convert a number into a string in a specific base.
Your task is to write such a function.
- the function may return the value or print it
- you must provide support for all bases between 2 and 36
- digits to use are
0123456789abcdefghijklmnopqrstuvwxyz
- all languages are allowed
- built in functions for this purpose are boring and thus forbidden
- shortest code wins