python2.4 generator expression > python2.3 list expression
Brian Beck
exogen at gmail.com
Mon Feb 21 12:37:48 EST 2005
Duncan Booth wrote:
> The difference between the original "reset the rightmost '1' bit", and your
> interpretation: "reset the rightmost bit" is the "'1'".
>
> The rightmost bit that is set is reset. So 0x10 -> 0, and 0x1010 -> 0x1000.
>
> If you want to extract the least significant set bit from a number 'x' you
> can use (x&-x):
My interpretation of Bryan's (mis?)interpretation (heh) was that since
in the numbers 2 and 10 (as in his examples), the least significant bit
was already 0, performing an operation that set it to 0 should result in
the number unchanged. As his tests show, this is not the case. This is
because the operation works only if the least significant bit actually
NEEDS to be unset. To zero the least significant bit unconditionally, we
can use:
x &= ~1
--
Brian Beck
Adventurer of the First Order
More information about the Python-list
mailing list