Skip to content

Instantly share code, notes, and snippets.

@nerflad
Last active April 3, 2016 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerflad/1d5954a88661ecdc669df54d3c4c87ce to your computer and use it in GitHub Desktop.
Save nerflad/1d5954a88661ecdc669df54d3c4c87ce to your computer and use it in GitHub Desktop.
Python 2: Convert base 10 number to desired base
# 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