Anonymous user
Non-decimal radices/Convert: Difference between revisions
Fixed task description English and added more syntax highlighting
(Added Java example) |
(Fixed task description English and added more syntax highlighting) |
||
Line 1:
{{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.
Write a second function which is passed a string and
The programs may be limited by the word size or other such constraint of a given language
▲The programs may be limited by the word size or other such constraint of a given language, and do not need to do error checking for negatives, bases less than 2, or inappropriate digits.
=={{header|Python}}==
<
def baseN(num,b):
return ((num == 0) and "0" ) or ( baseN(num // b, b).lstrip("0") + "0123456789abcdefghijklmnopqrstuvwxyz"[num % b])
Line 15 ⟶ 14:
s = baseN(k,16) # returns the string 1a
i = int('1a',16) # returns the integer 26
</
=={{header|Java}}==
|