Re: [CHALLENGE] finding rightmost zero bit



Brooks Moses wrote:
     if (.not. btest(n, 0))
       pos = 0
     elseif (.not. btest(n, 1))
       pos = 1
     elseif (.not. btest(n, 2))
       pos = 2
     elseif (.not. btest(n, 3))
       pos = 3
     elseif (.not. btest(n, 4))
       pos = 4
     elseif (.not. btest(n, 5))
       pos = 5
     elseif (.not. btest(n, 6))
       pos = 6
     elseif (.not. btest(n, 7))
       pos = 7

Correction: I'd misread the original program; all of the pos= values in this block need to be incremented by one. Note that, in this version -- unlike the original bart1 -- the incrementing can be done at programming time rather than at runtime, thereby illustrating some of the utility of loop-unrolling. :)


- Brooks


-- The "bmoses-nospam" address is valid; no unmunging needed. .



Relevant Pages