ffs(3c) DG/UX 4.30 ffs(3c)
NAME
ffs - Return the position of the first set bit in an
integer.
SYNOPSIS
int ffs(), bitnum, number;
bitnum = ffs(number);
where number is the integer tested for the set bit.
DESCRIPTION
The ffs function returns the position of the first bit set
to 1 in an integer; this function comes from the University
of California Berkeley UNIX (BSD) system.
RETURNS
The ffs function returns the first set bit, starting with
the least significant bit. For example, ffs(0) returns 0,
ffs(1) returns 1, and ffs(16) returns 5.
SEE ALSO
See also the bcopy, bcmp, and bzero functions.
EXAMPLE
The following program demonstrates the ffs function for each
power of two from 0 - 15 and 0.
/* Program test for the ffs() function */
#include <stdio.h>
int ffs(), i = 1;
main() {
printf("ffs(%#08x) = %d.\n", i, ffs(i));
do {
i <<= 1;
printf("ffs(%#08x) = %d.\n", i, ffs(i));
} while (i != 0);
return 0;
}
Licensed material--property of copyright holder(s) Page 1