Quantcast
Channel: What is the fastest/most efficient way to find the highest set bit (msb) in an integer in C? - Stack Overflow
Viewing all articles
Browse latest Browse all 36

Answer by jemin for What is the fastest/most efficient way to find the highest set bit (msb) in an integer in C?

$
0
0

The code:

    // x>=1;    unsigned func(unsigned x) {    double d = x ;    int p= (*reinterpret_cast<long long*>(&d) >> 52) - 1023;    printf( "The left-most non zero bit of %d is bit %d\n", x, p);    }

Or get the integer part of FPU instruction FYL2X (Y*Log2 X) by setting Y=1


Viewing all articles
Browse latest Browse all 36

Trending Articles