http://www.perlmonks.org?node_id=994023


in reply to Re: Which bit is set? (inverse of (1<<$value) operator)
in thread Which bit is set? (inverse of (1<<$value) operator)

Many thanks!

The lookup idea is nice and clean. I will use it as I only have 9 different bits.

However, your second option is the one I was (foolish) looking for. In my code, this could be the line:

# return the first less significant bit set. return $_ for grep { $bit & 1<<$_ } (0..8)';