Skip to content

Instantly share code, notes, and snippets.

@kuenishi
Last active July 28, 2020 13:27
Show Gist options
  • Save kuenishi/980f8be83a970f81b1acc4e1fe47df6e to your computer and use it in GitHub Desktop.
Save kuenishi/980f8be83a970f81b1acc4e1fe47df6e to your computer and use it in GitHub Desktop.
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