newlib-cygwin/newlib/libc/misc/ffs.c

47 lines
607 B
C
Raw Normal View History

2000-02-18 03:39:52 +08:00
/*
FUNCTION
<<ffs>>---find first bit set in a word
INDEX
ffs
ANSI_SYNOPSIS
#include <strings.h>
2000-02-18 03:39:52 +08:00
int ffs(int <[word]>);
TRAD_SYNOPSIS
#include <strings.h>
2000-02-18 03:39:52 +08:00
int ffs(<[word]>);
DESCRIPTION
<<ffs>> returns the first bit set in a word.
RETURNS
<<ffs>> returns 0 if <[c]> is 0, 1 if <[c]> is odd, 2 if <[c]> is a multiple of
2, etc.
PORTABILITY
<<ffs>> is not ANSI C.
No supporting OS subroutines are required. */
#include <strings.h>
2000-02-18 03:39:52 +08:00
int
_DEFUN(ffs, (word),
int word)
2000-02-18 03:39:52 +08:00
{
int i;
if (!word)
return 0;
i = 0;
for (;;)
{
if (((1 << i++) & word) != 0)
return i;
}
}