Convert a sequence of bits to a bit-string
Tim Chase
python.list at tim.thechases.com
Sat Dec 15 10:10:17 EST 2007
> does anybody know how to convert a long
> sequence of bits to a bit-string? I want to avoid this:
>
>>>> bit=0011010000000000000111111111111111000000000000000001111111010111111111111001
I do not think this does what you think it does...
http://docs.python.org/ref/integers.html
The leading zero(s) make(s) this an octal literal, not a binary
literal.
>>>> str(bit)
> '949456129574336313917039111707606368434510426593532217946399871489'
Which happens to be the result when the above octal
representation is converted to decimal.
> I would appreciate a prompt reply because I have my python assessment to
> submit. Thanks, Thomas
All you need to do is represent your bits in a way that actually
represents your bits. If you need
>>> help(
... # on possible functions to do this, I can give you a h
... int # that might point you in the right direction
... ) #regarding such base matters.
-tkc
More information about the Python-list
mailing list