print(int('111',2))
print(int('222',3))
print(int('333',4))
print(int('444',5))
print(int('555',6))
print(int('FFF',16))
"""
7
26
63
124
215
4095
"""
print(bin(10))
print(oct(10))
print(hex(10))
"""
0b1010
0o12
0xa
"""
tmp = "0123456789ABCDEF"
def convert(num, base):
q, r = divmod(num, base)
if q == 0:
return tmp[r]
else:
return convert(q, base) + tmp[r]
print(convert(10,2))
print(convert(10,3))
print(convert(10,4))
print(convert(10,5))
"""
1010
101
22
20
"""
또는
def convert(num, base):
result = ""
while num:
result += str(num % base)
num = num // base
return result[::-1]
tmp = "0123456789ABCDEF"
def convert(num, base):
q, r = divmod(num, base)
if q == 0:
return tmp[r]
else:
return convert(q, base) + tmp[r]
print(convert(int('a',16),2))
print(convert(int('4',5),3))
print(convert(int('2',3),4))
print(convert(int('11',2),5))
"""
1010
101
22
20
"""