Created
May 10, 2020 13:07
-
-
Save wesbasinger/492cf23f738a696dde764f32e31dadd0 to your computer and use it in GitHub Desktop.
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
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