![](/img/trans.png)
[英]error: bad operand types for binary operator '&&'. what does this error mean?
[英]What does the binary operator << mean?
在Java中,有>>,<<和>>>運算符。
根據Java doc
有符號的左移位運算符“ <<”將位模式向左移位,而有符號的右移位運算符“ >>”將位模式向右移位。 位模式由左操作數給出,移位位置的數量由右操作數給出。 無符號右移運算符“ >>>”將零移位到最左位置,而“ >>”之后的最左位置取決於符號擴展名。
我是二進制數據的新手,但我發現這種解釋有點含糊,沒有示例或用例。 有人可以給我這些操作員的例子或用例嗎?
謝謝,
有符號的左移位運算符“ <<”將位模式向左移位,而有符號的右移位運算符“ >>”將位模式向右移位。 位模式由左操作數給出,移位位置的數量由右操作數給出。 無符號右移運算符“ >>>”將零移位到最左位置,而“ >>”之后的最左位置取決於符號擴展名。
public class Test {
public static void main(String args[]) {
int a = 60; /* 60 = 0011 1100 */
int b = 13; /* 13 = 0000 1101 */
int c = 0;
c = a << 2; /* 240 = 1111 0000 */
System.out.println("a << 2 = " + c );
//this will shift the binary version of a to two bits left side and insert zero in remaining places
c = a >> 2; /* 215 = 1111 */
System.out.println("a >> 2 = " + c );
//this will shift the binary version of a to left by two bits right insert zero in remaining places
c = a >>> 2; /* 215 = 0000 1111 */
System.out.println("a >>> 2 = " + c );
//this will shift the binary of a to 3bits right insert zero in remaining places
}
}
我們有以下十進制和二進制數字:
8 = 0000 1000
15 = 0000 1111
10 = 0000 1010
然后,我們使用<<操作符,得到以下結果:
8 << 1-> 0001 0000 = 16
15 << 2-> 0011 1100 = 60
10 << 1-> 0001 0100 = 20
如您所見,運算符將數字的二進制表示形式移位右操作數給出的位數。 這樣做,您將獲得一個新號碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.