Bit to integer

Forgot that I was using bit values, got an error index out of bounds, so
I wrote little logarithm function to get my desired value.