Skip to content

Instantly share code, notes, and snippets.

@justcore69
Created March 18, 2024 03:05
Show Gist options
  • Save justcore69/0fc03a2962aa2abb009a442e310e9628 to your computer and use it in GitHub Desktop.
Save justcore69/0fc03a2962aa2abb009a442e310e9628 to your computer and use it in GitHub Desktop.
Python function for converting decimal numbers to numbers of any base
# maximum base - 36
def dec_to_base(a, b):
sym='0123456789abcdefghijklmnopqrstuvwxyz'
s=''
while a > 0:
s += sym[a%b]
a//=b
s=s[::-1]
return s
a=535673435
print('hex function:\t',hex(a)[2:])
print('dtb function:\t',dec_to_base(a,16))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment