python2.4 generator expression > python2.3 list expression
Bryan
belred at gmail.com
Mon Feb 21 11:51:31 EST 2005
Christos TZOTZIOY Georgiou wrote:
> On 21 Feb 2005 06:48:19 -0500, rumours say that Dan Sommers <me at privacy.net>
> might have written:
>
> [snip: snacktime posts code to count bits]
>
>
>>>Seems to work, is there a better way to do this?
>
>
> [Dan]
>
>>for c in range( 128 ):
>> even_odd = 0
>> print '%3d' % c,
>> while c:
>> c &= c - 1
>> even_odd = not even_odd
>> print int( even_odd )
>
>
> Just for the sake of people who haven't messed with bit manipulation in C or
> assembly, the effect of
>
> c &= c - 1
>
> is to reset the rightmost (less significant) '1' bit of a number (ie change it
> to '0').
i tried c &= c - 1 but i'm not getting the least significant or rightmost bit
reset to zero. am i misunderstanding something?
>>> 2 & 1 # 2 = 0x10; reset right most would be 0x10
0
>>> 10 & 9 # 10 = 0x1010; reset right most would be 0x1010
8
bryan
More information about the Python-list
mailing list