Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ffs.c « misc « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e4afe7a41728b400cb9cbbd6bff7a77a0428db5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
FUNCTION
	<<ffs>>---find first bit set in a word

INDEX
	ffs

ANSI_SYNOPSIS
	int ffs(int <[word]>);

TRAD_SYNOPSIS
	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.  */

int
ffs (word)
     int word;
{
  int i;

  if (!word)
    return 0;

  i = 0;
  for (;;)
    {
      if (((1 << i++) & word) != 0)
	return i;
    }
}