Couldn't you just take the binary log and round down? Okay ... just kidding.
Seriously, I think Mark had the right idea ... if you use a smaller table. This is similar to some ECC code I use for counting the number of 1's in a word. Removing the while() loop is left "as an exercise for the reader" ...
static const unsigned char list[16] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
// 0 = no bits set, 1 = 1st bit set, etc. unsigned char highest_bit(int iWord) { unsigned char iResult = 0; unsigned char iPass = 0; while (iWord != 0) { iResult = list[iWord & 0xF]; iWord >>= 4; if (iWord) iPass += 4; } return iResult + iPass; }
-rick