Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def convertNumber(base, n, to):
- digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- decimal = 0
- if base > 36 or to > 36:
- print("Numbers based on systems grather than 36 are not supported")
- return
- for exponent, i in enumerate(str(n)[::-1]):
- if digits.index(i) >= base:
- print("Value {0} is not written in {1} based system, conversion impossible").format(n, base)
- return
- decimal += digits.index(i) * base ** exponent
- result = ""
- while decimal >= 1:
- result += digits[decimal % to]
- decimal /= to
- print result[::-1]
- convertNumber(16, "DEAD", 10)
- convertNumber(10, 57005, 16)
Advertisement
Add Comment
Please, Sign In to add comment