Number base conversion is when you express a stored integer in an integer base, such as in octal (base 8) or binary (base 2). It also is involved when you take a string representing a number in a given base and convert it to the stored integer form. Normally, a stored integer is in binary, but that's typically invisible to the user, who normally enters or sees stored integers as decimal.



Task

Write a function (or identify the built-in function) which is passed a non-negative integer to convert, and another integer representing the base.

It should return a string containing the digits of the resulting number, without leading zeros except for the number   0   itself.

For the digits beyond 9, one should use the lowercase English alphabet, where the digit   a = 9+1,   b = a+1,   etc.

For example:   the decimal number   26   expressed in base   16   would be   1a.

Write a second function which is passed a string and an integer base, and it returns an integer representing that string interpreted in that base.

The programs may be limited by the word size or other such constraint of a given language. There is no need to do error checking for negatives, bases less than 2, or inappropriate digits.




with javascript_semantics
?{26,0b11010,0o32,0x1A,0X1a,#1A,0(16)1A}        -- displays {26,26,26,26,26,26,26}
printf(1,"%d == 0b%b == 0x%x\n",26)             -- displays 26 == 0b11010 == 0x1A
printf(1,"%d == o(62)%A\n",{26,{62,26}})        -- displays 26 == 0(62)Q
?to_number("1a",{},16)                          -- displays 26
include mpfr.e
mpfr f = mpfr_init()
mpfr_set_str(f,"110.01",2)
printf(1,"0b%s == %s\n",{mpfr_get_fixed(f,0,2),mpfr_get_fixed(f)}) -- 0b110.01 == 6.25
