Home     My Faqts     Contributors     About     Help    

faqts : Computers : Programming : Languages : Python

FAQTs repaired & updated!
Thanks for your patience...
Entry Add Entry Alert - Edit this Entry

Did You Find This Entry Useful?

0 of 1 people (0%) answered Yes
Recently 0 of 1 people (0%) answered Yes

how do i convert a number in base b to a number in base 10 using python

Jun 16th, 2004 20: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



© 1999-2004 Synop Pty Ltd