Implement the integral part logn base 2 with bit manipulations

Implement the integral part logn base 2 with bit manipulations

 

int integralPartOfLog(unsigned int n)
{

    int ret = 0;
    
    while (n > 0) {
        n = n>>1;
        ret++;
    }
    
    return ret-1;
}

 

posted @ 2016-01-27 11:31  Hygeia  阅读(198)  评论(0编辑  收藏  举报