One, bitwise operators
Any information is stored in binary form on the computer, "&", "|", "^" can be used as a bitwise operator in addition to being a logical operator.
&: Only the two bits that participate in the operation are 1,& and the result is 1, otherwise 0.
|: Only the result of the 0,| operation on both sides of the participating operation is 0, otherwise 1.
^: The two sides of the join operation are the same 0, the difference is 1.
~: Anti-code;
A number of different or the same number two times, the result is that number. Use a simple encryption idea. (Encrypt image code:)
ImportJava.io.*;classdemo4{ Public Static voidMain (string[] args)throwsException {File inFile=NewFile ("D:\\1.gif"); File OutFile=NewFile ("d:\\ encrypted. gif"); FileInputStream input=NewFileInputStream (InFile); FileOutputStream Output=NewFileOutputStream (OutFile); intContent=0; while((Content=input.read ())!=-1) {output.write (content^12); } output.close (); Input.close (); }} Encryption
Written question: Exchange two variables without using a third-party variable. (with ^)
class Demo5 { publicstaticvoid main (string[] args) { int a=3; int b=5; A=a^b; b=a^b; A=a^b; System.out.println (a+ "," +B); }} Swap variables
View Code
Second, shift operator
1. Shift Left (arithmetic shift "<<"): Empty 0, number of digits exceeded, discard.
Conclusion: The left shift is the equivalent of multiplying by 2 of the n-th power.
2. Move right (">>") shifted binary highest bit is 0, right shift, vacancy bit 0, highest bit is 1, vacancy is 1;
Conclusion: Right shift is equivalent to dividing by 2 n Power, n is the number of shifts.
3. Unsigned right Shift (">>>") right shift number of digits to the left of the operand (highest bit) uniform with 0 complement.
Third, operator order
Java Foundation--1--operator