Last active
April 3, 2016 21:24
-
-
Save nerflad/1d5954a88661ecdc669df54d3c4c87ce to your computer and use it in GitHub Desktop.
Python 2: Convert base 10 number to desired base
This file contains 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
# convert base10 number to desired base | |
def convertbase(num, base): | |
mods = [] | |
while num >= base: | |
mods.append(num % base) | |
num = num / base | |
if num <= base: | |
mods.append(num) | |
mods.reverse() | |
string = '' | |
for i in mods: | |
string += repr(i) | |
return int(string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment