short s = -1;
System.out.println(s >>>= 10);
byte b = -1;
System.out.println(b >>>= 10);
b = -1;
System.out.println(b>>>10);
结果是:
-1
-1
4194303
为什么啊?谢谢!
还有:
for(int j = 31; j >= 0; j--)
if(((1 << j) &  i) != 0)
     System.out.print("1");
else
     System.out.print("0");
是怎么实现二进制输出的啊?
非常感谢!
    System.out.println();

解决方案 »

  1.   

    知道了:
    If you use it with byte or short, you don’t get the correct results. Instead, these are promoted to int and right shifted, but then truncated as they are assigned back into their variables, so you get -1 in those cases. 
                                                                   ----thinking in java
      

  2.   

    for(int j = 31; j >= 0; j--)
    if(((1 << j) &  i) != 0)
         System.out.print("1");
    else
         System.out.print("0");将 1<<j ,将获得一个数字,假设是A,其二进制值,在j+1位上是1,其它位上都是0。A与i做按位与操作,如果i的第j+1位上是0,那么由于A只有j+1位上是1,其它位上都是0,结果必然是0;如果i的第j+1位上是1,那么由于A只有j+1位上是1,其结果是A,而且A一定不等于0。因此,如果结果不等0就打印1,显示第j+1位上是1;如果结果等0就打印0,显示第j+1位上是0。然后循环把每一个位上的数字都打印出来。