Determining combination of bits

Mitja nun at example.com
Mon Nov 8 17:12:00 EST 2004


Scott David Daniels wrote:
> Sean Berry wrote:
>> Just to set everyone's mind at ease... I haven't had a
>> homework assignment for about four years now.
> OK, then here's a great little bit of education:
>
>     n & -n == least significant bit of n

A lapse of mind?
>>> n = 6
>>> n & (-n)
2

You probably meant n&1 or perhaps n%2.





More information about the Python-list mailing list