Re: [CHALLENGE] finding rightmost zero bit



On 2005-08-30, *** Hendrickson <***.hendrickson@xxxxxxx> wrote:
>
> How about this for the fastest untested one-liner ;>
>
> pos = count(iand(not(n),ieor(n,n+1))> [0,1,2,4,8,16,32,64] )
>
> It seemed to work for the numbers up to 32 that I could
> mentally convert into binary. And, it's not only easily
> extensible, but it's obvious how it works!

To get the syntax right, i changed this to:

pos = count( iand(not(n), ieor(n,n+1)) > (/ 0,1,2,4,8,16,32,64 /) )

and it appears to give wrong results and bad timings, sorry ;-)

bartv@vonneumann:~/fortran$ ./time_findpos
huge(n) is 2147483647.
Enter first number: 1
Enter last number: 147483647
Total bits counted: 73741824
Brooks_WRONG's method did it from 1 to 147483647 in 1.21 seconds.
Total bits counted: 294967286
Bart1's method did it from 1 to 147483647 in 1.85 seconds.
Total bits counted: 294967286
Bart2's method did it from 1 to 147483647 in 1.84 seconds.
Total bits counted: 294967286
Bart3's method did it from 1 to 147483647 in 1.90 seconds.
Total bits counted: 294967286
Michel2's method did it from 1 to 147483647 in 1.86 seconds.
Total bits counted: 294967286
Brooks's method did it from 1 to 147483647 in 1.53 seconds.
Total bits counted: 293815079
***'s method did it from 1 to 147483647 in 2.31 seconds.

I did add it to the online version though :-)

Regards,
Bart

--
"Share what you know. Learn what you don't."
.