Binary Decimals in Python

Benjamin Kaplan benjamin.kaplan at case.edu
Tue Mar 30 11:37:36 EDT 2010


On Tue, Mar 30, 2010 at 11:13 AM, aditya <bluemangroupie at gmail.com> 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.
>
> - Aditya
> --

Because int stands for integer and 1.1 is not an integer. You get the
same error if you try doing int('1.1')

> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list