Jump to content

Non-decimal radices/Convert: Difference between revisions

m (→‎{{header|Python}}: Split long line)
Line 848:
 
=={{header|Python}}==
<lang python>defdigits baseN(num,b):= "0123456789abcdefghijklmnopqrstuvwxyz"
def baseN(num,b):
return (((num == 0) and "0" )
or ( baseN(num // b, b).lstrip("0")
+ "0123456789abcdefghijklmnopqrstuvwxyz"digits[num % b]))
 
# alternatively:
Line 859 ⟶ 860:
while num != 0:
num, d = divmod(num, b)
result += "0123456789abcdefghijklmnopqrstuvwxyz"digits[d]
return result[::-1] # reverse
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.