Answers for "largest power 2 less than N"

0

largest power 2 less than N

long largest_power(long N)
    {
        //changing all right side bits to 1.
        N = N| (N>>1);
        N = N| (N>>2);
        N = N| (N>>4);
        N = N| (N>>8);


    //as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
     2. 
                return (N+1)>>1;

    }
Posted by: Guest on August-13-2021

Browse Popular Code Answers by Language