imk0tter

Imk0tter

Nov 19th, 2010
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. def base(number,baseFrom,baseTo):
  2.     if baseFrom == 10: return __base(long(number),baseTo)
  3.     return __base(_base(str(number).lower(),baseFrom,len(str(number))),baseTo)
  4.    
  5. def _base(num,b1,len,mod=0):
  6.     charset = string.digits + string.ascii_lowercase
  7.     out = charset.index(num[len-1])*b1**mod
  8.     return out if len == 1 else out + _base(num,b1,len-1,mod+1)
  9.    
  10. def __base(num,b2):
  11.     charset = string.digits + string.ascii_uppercase
  12.     y = num%b2
  13.     out = charset[y]
  14.     return out if num == y else __base((num-y)/b2,b2) + out
Add Comment
Please, Sign In to add comment