按住Shift键在java中操作实现 [英] Shift operation implementation in java

查看:348
本文介绍了按住Shift键在java中操作实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近使用Java中的移位运算符,并注意到>> 运营商不具备的含义&GT相同;> C语言在Java >> 签订的转变,保持第一位在同一价值。在Java中等于C的转变是在>>> 运营商。左移操作符(<< )是C相同,只是转移忽略的第一位。

I recently used the shift operators in Java and noticed that the >> operator does not have the same meaning as >> in C. In Java >> is Signed shift that keeps the first bit at the same value. In Java the equivalent to C shift is the >>> operator. The left shift operator (<<) is the same as in C and just shifts ignoring the first bit.

我不知道的东西。


  • 为什么会做出这种改变?

  • 为什么不标记一致的,因此>>和&lt;&LT;签署移和>>>和&lt;&LT;&LT;是无符号?

  • 是否有一个签名移位运算符有什么用处?

推荐答案

有从未任何需要的标志感知左移,由于2:补重新presentation存储在最显著位的符号

There is never any need for a sign-aware left shift, since 2:s complement representation stores the sign in the most significant bit.

有一个值之间没有区别移1位左某种符号感知的方式,有什么可以做不同的。位左移,将在最显著位0,就大功告成了。

There's no difference between a value shifted one bit to the left in some kind of "sign-aware" manner, there's nothing you can do differently. Shift the bits to the left, insert a 0 in the least significant bit, and you're done.

通过符号数,右移是的的那么清楚,这就是为什么有两家运营商。

With signed numbers, shifting right is not so clear-cut, which is why there are two operators.

这篇关于按住Shift键在java中操作实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆