[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Golf (7 strokes is par!)



2000-05-01-13:12:47 Jeff Pinyan:
>   $_&$_-1
> 
> Do you happen to have the proof for why that is 0 for ONLY powers of 2? :)

For $_ & f($_) to equal zero, f($_) must clear the highest set bit
in $_. Subtracting 1 from a positive integer only clears the highest
set bit if the integer is a power of 2, otherwise it just dinks with
lower-order bits and leaves the highest one alone.

-Bennett

PGP signature