Re: [CHALLENGE] finding rightmost zero bit



Bart Vandewoestyne wrote:
On 2005-08-29, glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx> wrote:

    if(iand(j,Z'AAAAAAAA).NE.0) pos=pos+1
    if(iand(j,Z'CCCCCCCC).NE.0) pos=pos+2
    if(iand(j,Z'F0F0F0F0).NE.0) pos=pos+4
    if(iand(j,Z'FF00FF00).NE.0) pos=pos+8
    if(iand(j,Z'FFFF0000).NE.0) pos=pos+16

This appears to be not F-compliant.  Glen, can you make your
solution conform to the F-syntax?  I don't know how I should translate the
Z'AAAAAA and stuff to F as I don't know what that syntax means...

They are hex constants, so you can put in the decimal equivalent, though it will not look so nice.

Are you only allowing positive numbers as input, so that none
have the sign bit one?   Anyway...

     if(iand(j,-1431655766).NE.0) pos=pos+1
     if(iand(j,-858993460).NE.0) pos=pos+2
     if(iand(j,-252645136).NE.0) pos=pos+4
     if(iand(j,-16711936).NE.0) pos=pos+8
     if(iand(j,-65536).NE.0) pos=pos+16

This should return 0 for a -1 input, but maybe
you want 32 instead.

-- glen

.