Answers for "how to find the left most bit 1 in binary of any number"

C++
0

how to find the left most bit 1 in binary of any number

//C++ Code to find the value of 2^n = highestOneBit(). 
int highestOneBit(int i) {
    i |= (i >>  1);
    i |= (i >>  2);
    i |= (i >>  4);
    i |= (i >>  8);
    i |= (i >> 16);
    return i - (i >> 1);
}
Posted by: Guest on December-07-2020

Code answers related to "how to find the left most bit 1 in binary of any number"

Browse Popular Code Answers by Language