Commit | Line | Data |
---|---|---|
7b78baae DD |
1 | /* ffs -- Find the first bit set in the parameter |
2 | ||
3 | NAME | |
4 | ffs -- Find the first bit set in the parameter | |
5 | ||
6 | SYNOPSIS | |
7 | int ffs (int valu) | |
8 | ||
9 | DESCRIPTION | |
10 | Find the first bit set in the parameter. Bits are numbered from | |
11 | right to left, starting with bit 1. | |
12 | ||
13 | */ | |
14 | ||
15 | int | |
16 | ffs (valu) | |
17 | register int valu; | |
18 | { | |
19 | register int bit; | |
20 | ||
21 | if (valu == 0) | |
22 | return 0; | |
23 | ||
24 | for (bit = 1; !(valu & 1); bit++) | |
25 | valu >>= 1; | |
26 | ||
27 | return bit; | |
28 | } | |
29 |