美文网首页
Integer.highestOneBit

Integer.highestOneBit

作者: justlinzhihe | 来源:发表于2018-01-25 14:24 被阅读0次
    public static int highestOneBit(int i) {
        // HD, Figure 3-1
        i |= (i >>  1);
        i |= (i >>  2);
        i |= (i >>  4);
        i |= (i >>  8);
        i |= (i >> 16);
        return i - (i >>> 1);
    }

a|=b等价于a=a|b

1.当i>0时,返回的值是i的二进制最高位为1,右边全为0。
2.当i=0;返回0。
3.当i<0,返回Integer.MIN_VALUE.

相关文章

  • Integer.highestOneBit

    a|=b等价于a=a|b 1.当i>0时,返回的值是i的二进制最高位为1,右边全为0。2.当i=0;返回0。3.当...

  • Integer.highestOneBit(int i) 和 I

    1. 前言 Integer.highestOneBit(int i):求二进制除了最高位1保留,其他全部设置为0的...

网友评论

      本文标题:Integer.highestOneBit

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