Last active
July 28, 2020 13:27
-
-
Save kuenishi/980f8be83a970f81b1acc4e1fe47df6e 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
import sys | |
def char(i): | |
''' | |
0-9A-Z => sp(decimal) | |
''' | |
if i >= 0 and i <= 9: | |
return chr(ord('0')+i) | |
elif i < 36: | |
return chr(ord('A')+i-10) | |
else: | |
return f'🔣({i})' | |
def dtoh(h, d): | |
assert h > 0 | |
def max_digit(x): | |
c = 1 | |
while (h ** c) <= x: | |
c += 1 | |
return c | |
def to(x): | |
for i in range(max_digit(x)): | |
yield char(x % h) | |
x = x // h | |
return ''.join(reversed(list(to(d)))) | |
print(dtoh(int(sys.argv[1]), int(sys.argv[2]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment