I am trying to get the last 1 in a bitmask. More mathematically speaking, I have a number k, that can be written in its binary form as a sequence of 1 and 0. I want the "weight" or "index" of the last 1 in that number (from the right).
As an example, for the number 0b 10 0100 (36 in decimal), I want to get 3 (because the rightmost 1 is on 3rd position from the right)
I can find the first 1 easily (in my case 6), as the size of the number, or its base-2 log (rounded down +1), but what about the last one?
For information, I will use this in a dirty trick in MS Excel, described in https://stackoverflow.com/questions/5065432/excel-find-last-value-in-an-array/11246728#11246728