Shifts can be combined with the equal sign (<<= or >>= or >>>=). The lvalue is replaced by
the lvalue shifted by the rvalue. There is a problem, however, with the unsigned right shift
combined with assignment. 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. The following example demonstrates
this: 红色部分怎么理解?谢谢
the lvalue shifted by the rvalue. There is a problem, however, with the unsigned right shift
combined with assignment. 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. The following example demonstrates
this: 红色部分怎么理解?谢谢
解决方案 »
- Java中如何监控被调用的程序
- 结束线程的问题,高手指教啊,马上给分!
- 一个简单的java 程序 填空题 谢谢 各位了
- 假如IBM公司收购SUN公司,他们会谈成多少钱的收购价格?
- sql server2005连接
- 各位好,有谁用WEBSTART做过东西的请为我介绍一些学习书籍和网站,谈谈你们的经验。
- 如何读取任意文件,并将文件转换为字节数组?
- JBuilder->Wizard->Native Executive Archive下的问题
- 如何判断一个点在一个矩形内?(20分)
- JB老是自做聰明的把中文輸入法調出來,﹐怎麼解決這個問題?
- 菜鸟问题!麻烦大家解决下!
- 请问学习java gis开发应该先学习什么基础知识?使用什么开发工具?
为什么会得到-1,还有个问题啊,高位是左边还是右边???
public static void main(String[] args) {
byte b=-2;
System.out.println(Integer.toBinaryString(b));
b>>>=10;
System.out.println(Integer.toBinaryString(b));
}
}result:
11111111111111111111111111111110
11111111111111111111111111111111
我不理解的是,为什么不管b是多少,b>>>=10之后都为-1???????
或者是报的错?
不知道这里作者指的in those cases到底是什么.
具体结果肯定还与原来的值以及移动的位数有关系,写个例子就测试出来了.
System.out.println(Integer.toBinaryString(b));
b>>>=3;
System.out.println(Integer.toBinaryString(b));
System.out.println(b);
System.out.println(Integer.toBinaryString(b));
b>>>=2;
System.out.println(Integer.toBinaryString(b));
System.out.println(b);