summaryrefslogtreecommitdiff
path: root/lib/libc/strings/ffs.c
blob: 2c49cf4dfd34932eb92a0bb728dafc6f762213d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int ffs(int i)
{
	if (i == 0) {
		return 0;
	}

	int pos = 1;
	unsigned int u = (unsigned int)i;

	while ((u & 1U) == 0U) {
		u >>= 1;
		pos++;
	}

	return pos;
}