1 2 3 4 5 6 7 8 9 10 11 12 13 14
int ffsl(long i) { if (i == 0) return 0; int pos = 1; unsigned long u = (unsigned long)i; while ((u & 1UL) == 0UL) { u >>= 1; pos++; } return pos; }