美文网首页
Integer类中的numberOfLeadingZeros(i

Integer类中的numberOfLeadingZeros(i

作者: 03ca2835cf70 | 来源:发表于2019-11-26 10:10 被阅读0次

    https://www.jianshu.com/p/2c1be41f6e59

    源码:

       public static int numberOfLeadingZeros(int i) {
            //
            if (i == 0)    //步骤一
                return 32;
            int n = 1;  
            //步骤二
            if (i >>> 16 == 0) { n += 16; i <<= 16; }//分析一
            if (i >>> 24 == 0) { n +=  8; i <<=  8; }
            if (i >>> 28 == 0) { n +=  4; i <<=  4; }
            if (i >>> 30 == 0) { n +=  2; i <<=  2; }
            n -= i >>> 31;//分析二
            return n;
        }
    
    

    作者:ohDarling
    链接:https://www.jianshu.com/p/2c1be41f6e59
    来源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

    相关文章

      网友评论

          本文标题:Integer类中的numberOfLeadingZeros(i

          本文链接:https://www.haomeiwen.com/subject/gyfewctx.html