Skip to content

Instantly share code, notes, and snippets.

@Aaron1011
Created February 4, 2013 23:06
Show Gist options
  • Save Aaron1011/4710606 to your computer and use it in GitHub Desktop.
Save Aaron1011/4710606 to your computer and use it in GitHub Desktop.
import string
_CHARS = string.digits + string.uppercase
def itob(n, base):
cur_num = n % base
final = []
while n > 0:
final.append(_CHARS[cur_num])
n /= base
cur_num = n % base
final.reverse()
return "".join(final)
def itob_recur(n, b):
if n == 0:
return ""
final = [_CHARS[n % b], itob_recur(n / b, b)]
final.reverse()
return "".join(final)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment