The linked C code read:
for (ecx = 0; ecx < 32; ecx++) {
if ((1 << ecx) & eax) {
ebx = ecx;
}
}
The first step is simply asking "what does this code do?" It loops 0 through 31. It tests for specific bits (1 <<
variable). If a bit is set,
it records the offset -- but keeps running the loop. At the end, what is
left in ebx? The offset of the highest set bit.
In x86 assembly, there is an instruction that performs exactly this way: BSR,
or "Bit Search Reverse". So using "bsr %eax,%ebx" will scan eax and set ebx
with the offset of the highest bit. In machine code, this is "\x0f\xbd\xd8".