What is the most efficient way to find out how many bits are needed to represent some random int number? For example number 30,000 is represented binary with
So it needs 15 bits
For more advanced methods, see here http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
Note that this computes the index of the leftmost set bit (14 for 30000). If you want the number of bits, just add 1.