Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def base(number,baseFrom,baseTo):
- if baseFrom == 10: return __base(long(number),baseTo)
- return __base(_base(str(number).lower(),baseFrom,len(str(number))),baseTo)
- def _base(num,b1,len,mod=0):
- charset = string.digits + string.ascii_lowercase
- try:
- out = charset.index(num[len-1])*b1**mod
- except:
- out = 0
- return out if len == 1 else out + _base(num,b1,len-1,mod+1)
- def __base(num,b2):
- charset = string.digits + string.ascii_uppercase
- y = num%b2
- out = charset[y]
- return out if num == y else __base((num-y)/b2,b2) + out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement