Binary Decimals in Python

aditya bluemangroupie at gmail.com
Tue Mar 30 17:54:43 CEST 2010


On Mar 30, 10:37 am, Benjamin Kaplan <benjamin.kap... at case.edu> wrote:
> On Tue, Mar 30, 2010 at 11:13 AM, aditya <bluemangrou... 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
>
>

That makes sense. The closest thing I've found is this question on
StackOverflow: http://stackoverflow.com/questions/1592158/python-convert-hex-to-float

It seems to me that adding a conversion feature to floats would be a
lot more intuitive.



More information about the Python-list mailing list