Bitwise operators
All data in Java is performed in the form of binary data, that is, if it is an int variable, the bitwise operation must be transformed into binary data;
The result of a bit binary with, or, XOR, or operation is as follows:
Package com.test; Public class Test { publicstaticvoid main (string[] args) { int x = 3; int y = 6; & y); | y); ^ y);} }
Running Result: 2,7,5
In the computer's data representation only defines a positive number representation, and does not define a negative number representation, so, negative numbers are generally used in the form of complement , positive number of the original code, anti-code, and complement are the same, negative anti-code is in addition to the sign bit is 1, the other bits are reversed, complement is "Anti code +1"
Package com.test; Public class Test { publicstaticvoid main (string[] args) { int x =-3; System.out.println (~x); }}
Operation Result: 2
Java Bitwise operators