Determining combination of bits

Diez B. Roggisch deetsNOSPAM at web.de
Mon Nov 8 23:12:21 CET 2004


> A lapse of mind?
>>>> n = 6
>>>> n & (-n)
> 2
> 
> You probably meant n&1 or perhaps n%2.

No, the exact right thing: 6 is binary

110

with the least significant bit beeing 

10

thus the decimal value of 2. 

Albeit I have to admit that I didn't know the trick.
-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list