The following bitwise operation can be used to find /isolate the position of the right most bit in the data.
myVar & -myVar
How does this work?
Thius method relies on the fact that you are using two’s complement to store a negative number (usually the case) rather than using a sign bit.
myVar = 5 // hence myVar=0101
-myVar=-5 // hence -myVar=1011 – in two’s complement, hence….
myVar & -myVar = ? // ? = 0001,
// Hence showing that the right most bit of myVar is infact in the far right position
Try it out! This will work with any bit pattern!