Why not use the next two bits different from the leading bit. First you can split the number into 8 bits, and the next two bits - divide each bit into four. In this case, you can use a very fast switch operation.
Change If you think using a logarithm is a viable solution. Here is the general algorithm:
Let a be the base of the logarithm, and the range (b_min, b_max) = (32,8191) . You can find the base using the formula:
log(b_max/b_min) / log(a) = 32 bin
which give you a~1.1892026 . If you use this as a logarithm base, you can map the range (b_min, b_max) to (log_a(b_min), log_a(b_max)) = (20.0004,52.0004) .
Now all you have to do is subtract the whole element 20.0004 to get the range (0,32) . It ensures that all elements are logarithmically homogeneous. Done
Note. Or the item may fall out of range due to a numerical error. You must calculate it to get the exact value.
Note2: log_a (b) = log (b) / log (a)
unsym
source share