Binary Decimals in Python

MRAB python at mrabarnett.plus.com
Tue Mar 30 11:54:08 EDT 2010


aditya wrote:
> To get the decimal representation of a binary number, I can just do
> this:
> 
> int('11',2) # returns 3
> 
> But decimal binary numbers throw a ValueError:
> 
> int('1.1',2) # should return 1.5, throws error instead.
> 
> Is this by design? It seems to me that this is not the correct
> behavior.
> 
int() returns an integer (hence the name!), so it should never return a
float anyway.

What you want is for float() to accept a base, but that is rarely
needed.



More information about the Python-list mailing list