You must be kidding!
Logs to find bit numbers? Do you have any idea how much processing power that takes if there isn't a floating point unit?
Tim has the right idea on how the algorithm works, but most new PLCs have and ENC or Encode instruction. Also see Decode.
Some PLCs have a different name for this function. RTFM.
Omron has a instruction that can find a bit out of 16 16bit registers.
BTW, on a DSP I convert the integer to float and use the exponent. I have the benefit of floating point.
Tim's method works ok on a processor that can't handle bytes. When I do this I check the whole 32 bits for a bit. Then check to see if the bits are set in the lower or upper 16 bits. Then I check to see if the bit is set in the upper and lower byte. I shift only bytes with bits set. This limits the amount of shifts to 8.
More tidbits...
If you really want to master bit manipulation do a seach on google for "chess bit boards". Chess programmers are the master of bit manipulation. The concept of treating bits as sets will make you think about bits in new ways.
I have watched an older thread on counting bits. Check this out:
bitcount will be the number of bits set in register.
Code:
bitcount = 0;
while ( register <> 0 )
register = register and ( register - 1 )
bitcount = bitcount + 1;
end while
Notice that it only loops as many times as there are bits - 1. This is therefore extremely efficient when the bits are few. If there are likely to be more bits than zeros then not the register. Then you will be counts 0s.