[SciPy-User] Inverse of binary_repr

Warren Weckesser warren.weckesser@enthought....
Tue Mar 27 09:06:07 CDT 2012


On Tue, Mar 27, 2012 at 9:03 AM, Alexander Borghgraef <
alexander.borghgraef.rma@gmail.com> wrote:

> Hi all,
>
>  Is there an inverse function of binary_repr, which takes a binary string
> representation of a number ( like '100') and returns an integer?
>
>

Use the optional second argument of int(), which is the base:

In [1]: s = "1001"

In [2]: int(s, 2)
Out[2]: 9


Warren


> --
> Alex Borghgraef
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120327/c384ebfa/attachment-0001.html 


More information about the SciPy-User mailing list