Skip to content

Instantly share code, notes, and snippets.

@badgateway666
Created September 27, 2018 13:48
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 badgateway666/e4752dbad29c4b45c34da99c86e310ee to your computer and use it in GitHub Desktop.
Save badgateway666/e4752dbad29c4b45c34da99c86e310ee to your computer and use it in GitHub Desktop.
Decimal Number into different base
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