Non-decimal radices/Convert: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: Split long line) |
(→{{header|Python}}: factorize) |
||
Line 848: | Line 848: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
<lang python> |
<lang python>digits = "0123456789abcdefghijklmnopqrstuvwxyz" |
||
def baseN(num,b): |
|||
return (((num == 0) and "0" ) |
return (((num == 0) and "0" ) |
||
or ( baseN(num // b, b).lstrip("0") |
or ( baseN(num // b, b).lstrip("0") |
||
+ |
+ digits[num % b])) |
||
# alternatively: |
# alternatively: |
||
Line 859: | Line 860: | ||
while num != 0: |
while num != 0: |
||
num, d = divmod(num, b) |
num, d = divmod(num, b) |
||
result += |
result += digits[d] |
||
return result[::-1] # reverse |
return result[::-1] # reverse |
||