How to test whether bit is set within a flag with Python ?

Jess Jess-198700987 at hotmail.com
Wed May 12 22:23:34 EDT 2010


Cheap Chanel Watches for sale at: http://www.luxuryowner.net/

Chanel Watches collection: 
http://www.luxuryowner.net/replica-chanel-watches.html

Chanel J12 Automatic Watches: 
http://www.luxuryowner.net/Chanel-J12-Automatic-Watches.html

Chanel J12 Quartz Watches: 
http://www.luxuryowner.net/Chanel-J12-Quartz-Watches.html


"MRAB" <python at mrabarnett.plus.com> 
??????:mailman.117.1273689672.32709.python-list at python.org...
> robert somerville wrote:
>> I am trying to determine how to test whether variors bits are set within 
>> a byte (or larger flag) , the python 'and' and 'or' do not seem to be 
>> doing what i want .. does anybody have some sample code showing how to do 
>> it ??
>>
>> e.g. (in "C")
>>
>> unsigned char a = 6;
>>
>> is 3rd bit set ??
>>
>> a & 4 =,  true in this case ....
>>
> 'and', 'or' and 'not' are Boolean.
>
> Python borrows its bitwise operators from C:
>
>     &     bitwise and
>     |     bitwise or
>     ^     bitwise xor
>     ~     bitwise not (ones' complement)
>     <<    shift left
>     >>    shift right
>
> You also need to remember that Python's integers are of (virtually)
> unlimited length. 





More information about the Python-list mailing list