Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Java Operator Precedence

  1. 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.

  2. There is no unsigned left shift operator in Java. https://www.quora.com/Why-is-there-no-unsigned-left-shift-operator-in-Java

System.out.println(1 << 5)
32
null
System.out.println(1 << 5 - 1)
16
null
System.out.println(1 << 30)
1073741824
null
System.out.println(1 << 31)
-2147483648
null
System.out.println(Integer.toBinaryString(1 << 31))
10000000000000000000000000000000
null

The shift oprator is cyclical.

System.out.println(Integer.toBinaryString(1 << 32))
1
null

Unsigned Right Shift Operator (>>>)

System.out.println(1 >>> 31);
0
null
System.out.println(Integer.toBinaryString(-4))
11111111111111111111111111111100
null
System.out.println(-4 >>> 28);
15
null
System.out.println(Integer.toBinaryString(-1))
11111111111111111111111111111111
null
System.out.println(-4 >> 28)
-1
null
System.out.println(1 <<< 3);
illegal start of type
 System.out.println(1 <<< 3)
                          ^  

illegal start of expression
 System.out.println(1 <<< 3)
                           ^^ 

')' expected
 System.out.println(1 <<< 3)
                            ^

';' expected

^

reached end of file while parsing
 }
  ^
System.out.println(1 << 32)
1
null
System.out.println(1 << 33)
2
null
System.out.println(~0)
-1
null
System.out.println(Integer.toBinaryString(-1))
11111111111111111111111111111111
null