how to get bit info
Grant Edwards
invalid at invalid.invalid
Thu Jun 17 16:29:36 EDT 2010
On 2010-06-17, Stephen Hansen <me+list/python at ixokai.io> wrote:
>>>> BIT_1 = 1 << 0
>>>> BIT_2 = 1 << 1
...
> Basically, those BIT_X lines are creating numbers which have *only* the
> specified bit set. Then you do "byte & BIT_X", and that will return 0 if
> the byte doesn't have the specified bit in it. You can then set the bit
> with "byte | BIT_X", and unset the bit with "byte ^ BIT_X".
Just to clarify, "byte ^ BIT_X" inverts (toggles) bit X.
If you want to make sure bit X is a 0 (which is what people usually
mean by "unset"), you do "byte & ~BIT_X"
--
Grant Edwards grant.b.edwards Yow! I know things about
at TROY DONAHUE that can't
gmail.com even be PRINTED!!
More information about the Python-list
mailing list