thinking in java哪一页?

解决方案 »

  1.   

    表达的是什吗意思,《scjp认证指南》里也这么说,几乎和thinking in java英文版用了一样的话
      

  2.   

    这么多人看过thinking in java难道就没有人能顺手给我讲讲吗
      

  3.   

    他们都是从这里(JLS)来的:http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5121

    The type of each of the operands of a shift operator must be a primitive integral type, or a compile-time error occurs. Binary numeric promotion (§5.6.2) is not performed on the operands; rather, unary numeric promotion (§5.6.1) is performed on each operand separately. The type of the shift expression is the promoted type of the left-hand operand.
    If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (§15.22.1) with the mask value 0x1f. The shift distance actually used is therefore always in the range 0 to 31, inclusive.If the promoted type of the left-hand operand is long, then only the six lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (§15.22.1) with the mask value 0x3f. The shift distance actually used is therefore always in the range 0 to 63, inclusive.
    我也没看懂为什么要用一个5位/6位的mask,哈哈哈哈哈
      

  4.   

    是这个意思:X >>> Y当X为int时,Y不得大于32;当X为long时,Y不得大于64;如果Y大于32或64,则X只移动32位或64位,因为不管再移动多少位,结果都是一样为0。
    这主要是防止程序员写错程序,Y太大,导致cpu处理时间过长。所以执行上面的语句时,
    只用Y的低5位(最大32)或低6位(最大64)。明白了吗?见java2认证学习指南(英文原版)第37、38页。
      

  5.   

    x>>y
    当X为int时,Y可以大于32,例如:
    class Test {
      public static void main(String[] args) {
      int i=32;
      System.out.println(""+(i>>>33));
    }
    }输出:16
    表明>>>32等于>>>1
    同样<<,>>Y都可超过32
      

  6.   

    俺也明白了,被mask的是Y,不是X,俺代表拉哥谢谢,哈哈哈哈哈