What on earth is "i-esim 0"?
For locating and counting individual bits, look up
__builtin_ffs(),
__builtin_clz(),
__builtin_ctz() and
__builtin_popcount(). While they are
GCC built-ins, they are supported by most other C compilers too.
Each of these operations can be written using portable code in a few lines; most of them are listed in Wikipedia, others in different optimization articles all over the web. The variant I'd recommend would heavily depend on exactly what you need to find out. It is a good bet that the compiler builtins are faster, though.