The Bitwise operators has relative low precedence. They have lower precedence than arithmatical operators. It is suggested that you use parentheses when you mix lower precendenc (bitwise opertors, ternary opertor, etc.) and high precendenc operators together.
There is no unsigned left shift operator in Java. https://www.quora.com/Why-is-there-no-unsigned-left-shift-operator-in-Java
In [7]:
System.out.println(1 << 5)
Out[7]:
In [6]:
System.out.println(1 << 5 - 1)
Out[6]:
In [13]:
System.out.println(1 << 30)
Out[13]:
In [7]:
System.out.println(1 << 31)
Out[7]:
In [14]:
System.out.println(Integer.toBinaryString(1 << 31))
Out[14]:
The shift oprator is cyclical.
In [15]:
System.out.println(Integer.toBinaryString(1 << 32))
Out[15]:
Unsigned Right Shift Operator (>>>)¶
In [8]:
System.out.println(1 >>> 31);
Out[8]:
In [3]:
System.out.println(Integer.toBinaryString(-4))
Out[3]:
In [1]:
System.out.println(-4 >>> 28);
Out[1]:
In [5]:
System.out.println(Integer.toBinaryString(-1))
Out[5]:
In [4]:
System.out.println(-4 >> 28)
Out[4]:
In [12]:
System.out.println(1 <<< 3);
In [3]:
System.out.println(1 << 32)
Out[3]:
In [4]:
System.out.println(1 << 33)
Out[4]:
In [6]:
System.out.println(~0)
Out[6]:
In [5]:
System.out.println(Integer.toBinaryString(-1))
Out[5]: