Returns the index of the highest bit set in an int
Download (right click, save as, rename as appropriate)
1 2 3 4 5
int highestBitSet(unsigned int x) { int i=0, j=1; for (; j <= x && i < sizeof(x) * CHAR_BIT; i++, j <<= 1); return i-1; }