Want to record the basic knowledge of Java, if you encounter a miscellaneous problem, also add to here, no longer another new blog
1. Shift operation (<<, >>)
Public Static void Main (string[] args) { int a = 8; // 8<<3--8 * (2 of 3 times) System.out.println ("8<<3----->" + (8<<3)); // 8>>3--8/(2 of 3 times) System.out.println ("8>>3----->" + (8>>3)); }
8<<3----->648>>3----->1
The shift operation is the fastest in the computer.
Take 11 as an example
11 binary corresponding is 1011
11<<3 Move right 3-bit to get 1011--and decimal 88 "11* (2 of 3)"
11>>3 move left 3-bit to get 1--and decimal 1 "11/(2 3)"
Put on the code to verify it.
Public Static void Main (string[] args) { int a = one; System.out.println (Integer.tobinarystring (a)); System.out.println (Integer.tobinarystring (a<<3) + "decimal:" + (a<<3)); System.out.println (Integer.tobinarystring (a>>3) + "decimal:" + (a>>3)); }
101,110,110,000 binary: 8,810 binary: 1
2. Bitwise non-operator (~)
Public Static void Main (string[] args) { int A =-9; int b = 9; int c = 0; // ~a--(-a-1) System.out.println ("~a---->" + (~a)); System.out.println ("~b---->" + (~b)); System.out.println ("~c---->" + (~c)); }
~a---->8~b---->-10~c---->-1
Java Fundamentals (long-term updates)