In just a few CPU instructions, the truncated base 2 logarithm of any integer can be computed for any integer from -2^63 … 2^63 – 1. This has interesting applications in being able to rapidly access logarithmically increasing arrays. The Linux GCC compiler provides a built in function, __builtin_clzll, to allow this CPU instruction to be used directly from C and C++ on a 64 bit integer.
i | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 31 | 32 floor(log2(i)) | NA | 0 | 1 | 1 | 2 | 2 | 2 | 2 | 3 | 3 | 4 | 4 | 5 63 - clzll(i) | ~1 | 0 | 1 | 1 | 2 | 2 | 2 | 2 | 3 | 3 | 4 | 4 | 5