How can I get the most significative 1-bit index from an unsigned integer (uint16_t
)?
Example:
uint16_t x = // 0000 0000 1111 0000 = 240
printf("ffs=%d", __builtin_ffs(allowed)); // ffs=4
There is a function (__builtin_ffs
) that return the least significative 1-bit (LSB) from a unsigned integer.
I want something opposite, I want some function which returns 8
applied to above example.
Remark: I have tried building my own function but I have found some problems with datatype size, which depends by compiler.