Created
February 4, 2013 23:06
-
-
Save Aaron1011/4710606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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