If I have some integer n, and I want to know the position of the most significant bit (that is, if the least significant bit is on the right, I want to know the position of
What about
int highest_bit(unsigned int a) { int count; std::frexp(a, &count); return count - 1; }
?