Entry
how do i convert a number in base b to a number in base 10 using python
Jun 16th, 2004 03:34
Thomas Samson, bob leron, http://docs.python.org/lib/built-in-funcs.html,http://aspn.activestate.com/ASPN/Cookbook/Python/
You use 'int':
int([x[, radix]])
if x is a string, it is converted using the optionnal parameter radix
as a base.
radix must be in the range [2, 36], or zero
src_nbr = "101010"
dec = int(src_nbr, 2)
If you want to do this with radix outside the [2,36] range, look at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286