read string in bits

Hendrik van Rooyen mail at microcorp.co.za
Wed Jan 14 03:15:42 EST 2009


 "Chris Rebert" <clp2 at rebertia.com> wrote:

> It's not quite clear to me what you mean, but here are 2 guesses:
> - If you want to convert an ASCII character to its ASCII integer
> value, use ord()
> - If you want to convert an integer into a string of its base-2
> representation, use bin() [requires Python 2.6, I think]

Another case:

>>> s = '1010101'
>>> int (s,2)
85
>>> 

Works almost anywhere, AFAIK.

- Hendrik




More information about the Python-list mailing list