Created
September 27, 2018 13:48
-
-
Save badgateway666/e4752dbad29c4b45c34da99c86e310ee to your computer and use it in GitHub Desktop.
Decimal Number into different 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
def convert_to_base(input, outputbase): | |
output = [] | |
next_number = input | |
while next_number > 0: | |
print("NextNumber: {0} | Base: {1} --> Next_number = {2} Rest = {3}".format(next_number, | |
outputbase, | |
int(next_number/outputbase), | |
int(next_number % outputbase))) | |
rest = int(next_number % outputbase) | |
next_number = int(next_number / outputbase) | |
output.insert(0, rest) | |
outputstring = "" | |
for n in output: | |
if n > 9: | |
next = chr(65+n-10) | |
outputstring += str(next) | |
else: | |
outputstring += str(n) | |
print(outputstring) | |
convert_to_base(270, 16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment