How can you get the index of the second least significant bit? For example if x=136
this should be 8
(using 1-indexing).
The indexing is from the least significant bit. For example:
bin(136)
'0b10001000'
If x=88
the output should be 5
.
To make this work properly we also need a test that the number of bits set is at least 2. Luckily bin(x).count('1')
will do that.
There are answers for finding the least significant bit at return index of least significant bit in Python (although at least one of the answers seems to be wrong).