Back to index

cell-binutils  2.17cvs20070401
ffs.c
Go to the documentation of this file.
00001 /* ffs -- Find the first bit set in the parameter
00002 
00003 @deftypefn Supplemental int ffs (int @var{valu})
00004 
00005 Find the first (least significant) bit set in @var{valu}.  Bits are
00006 numbered from right to left, starting with bit 1 (corresponding to the
00007 value 1).  If @var{valu} is zero, zero is returned.
00008 
00009 @end deftypefn
00010 
00011 */
00012 
00013 int
00014 ffs (register int valu)
00015 {
00016   register int bit;
00017 
00018   if (valu == 0)
00019     return 0;
00020 
00021   for (bit = 1; !(valu & 1); bit++)
00022        valu >>= 1;
00023 
00024   return bit;
00025 }
00026