Created
March 18, 2024 03:05
-
-
Save justcore69/0fc03a2962aa2abb009a442e310e9628 to your computer and use it in GitHub Desktop.
Python function for converting decimal numbers to numbers of any base
This file contains hidden or 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
# 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