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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
网友评论