But your lookup table will waste memory, as it will have 256 entries.
Here's a proof-of-concept code that does (not quite) exactly what the OP wanted to achieve:
It is full of magic numbers and without reading the HOWTO, it will be very hard to understand what the code is doing.Code:int ffc(char c) { c = ~c; static const char debruijn[8] = {0, 1, 2, 4, 7, 3, 6, 5}; return debruijn[((c & -c) * 23) >> 5]; }
Greets,
Philip