binary string question

Alex Martelli aleaxit at yahoo.com
Fri Nov 7 18:56:46 EST 2003


Ben Finney wrote:

> On Fri, 07 Nov 2003 23:20:05 GMT, Alex Martelli wrote:
>> Dan Jones wrote:
>>> I'm trying to figure out how to get bit operators to work on a binary
>>> string.
>>
>> You can access an individual byte simply by indexing the string
> 
> It's possible the original poster is asking (ambiguously) about treating
> a string consisting of '0' and '1' digits, as a binary number.

oh, then:

x = long(thestringof0sand1s, 2)

might work, but to access individual bits, bytes, etc, you need masks and 
shifts.


Alex







More information about the Python-list mailing list