hi Pommie.
your code doesn't do what it should.
Yes it does.
1. your code starts counting bits from left and not from right
I work in little endian and you didn't state which. Also, in your example, the 8th bit from MSB is set whereas the 8th bit from LSB isn't.
2. your code it not efficient, it masks EVERY bit until it counts count '1' bits, and then return index.
this give worst case of 32 masking operations.
I don't see any other way to do it. Plus, efficient can mean less code rather than more speed. Again, you didn't state which.
I'd like to make the code efficient.
good luck with that.