Log base 2 of IEEE 32 bit float
Integer log base 10 of an integer
This one is amazing
Code:
const int r;
int c;
c = *(const int *) &v;
c = ((((c - 0x3f800000) >> r) + 0x3f800000) >> 23) - 127;
Integer log base 10 of an integer
This one is amazing
Code:
unsigned int v;
int r;
int t;
static unsigned int const PowersOf10[] =
{1, 10, 100, 1000, 10000, 100000,
1000000, 10000000, 100000000, 1000000000};
t = (IntegerLogBase2(v) + 1) * 1233 >> 12;
r = t - (v < PowersOf10[t]);