[comp.os.minix] ffs

tholm@uvicctr.UUCP (Terrence W. Holm) (09/14/88)

EFTH MINIX report #42  - September 1988 -  ffs(3)


There follows an implementation of ffs(3) for MINIX.
Please consider this public domain software. A "man"
page is included.

----------------------------------------------------------
echo x - ffs.3
gres '^X' '' > ffs.3 << '/'
XSUBROUTINES
X    ffs(3)		- find first bit set
X
XINVOCATION
X    int ffs( word )
X      int word;
X
XEXPLANATION
X    The index of the first bit set in <word> is returned.
X
XRESULTS
X    0   : <word> is zero.
X    1   : Right-most bit is set.
X    2   : Right-most bit is clear, the next bit is set.
X    ...
X    16  : Only the left-most bit is set, (for 16 bit int's).
/
echo x - ffs.c
gres '^X' '' > ffs.c << '/'
X/*  ffs(3)
X *
X *  Author: Terrence W. Holm          Sep. 1988
X */
X
X
Xint ffs( word )
X  int word;
X
X  {
X  int i;
X 
X  if ( word == 0 )
X    return( 0 );
X
X  for ( i = 1;  ;  ++i, word >>= 1 )
X    if ( word & 1 )
X	return( i );
X  }
/
----------------------------------------------------------

		Edwin L. Froese
		  uw-beaver!ubc-cs!mprg!handel!froese

		Terrence W. Holm
		  uw-beaver!uvicctr!tholm