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
- out = charset.index(num[len-1])*b1**mod
- 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
Add Comment
Please, Sign In to add comment