1# add as many different characters as you want
2alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
3
4
5def convert(num, base=2):
6 assert base <= len(alpha), f"Unable to convert to base {base}"
7 converted = ""
8 while num > 0:
9 converted += alpha[num % base]
10 num //= base
11
12 if len(converted) == 0:
13 return "0"
14 return converted[::-1]
15
16
17print(convert(15, 8)) # 17
1alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
2
3
4def convert(num, base=2):
5 assert base <= len(alpha), f"Unable to convert to base {base}"
6 converted = ""
7 while num > 0:
8 converted += alpha[num % base]
9 num //= base
10
11 if len(converted) == 0:
12 return "0"
13 return converted[::-1]
14
15
16print(convert(15, 8)) # 17