Skip to content

Instantly share code, notes, and snippets.

@wesbasinger
Created May 10, 2020 13:07
Show Gist options
  • Save wesbasinger/492cf23f738a696dde764f32e31dadd0 to your computer and use it in GitHub Desktop.
Save wesbasinger/492cf23f738a696dde764f32e31dadd0 to your computer and use it in GitHub Desktop.
def convert(num, base):
highest_power = 0
while base**highest_power < num:
highest_power += 1
result = ""
while highest_power >= 0:
multiplier = num // base**highest_power
result += str(multiplier)
num -= multiplier*(base**highest_power)
highest_power -= 1
if result[0] == "0":
return result[1:]
else:
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment