[JavaSE] bit operators (& | ^) and javase Operators
Bitwise operations directly calculate binary data
Shift left <
Shift right>
First, replace the integer with four 8bit 0000-0000 0000-0000 0000-0000 0000-0000
This binary is moved left and right, and the removed end is filled with 0.
Rule:
6 <3 means 6 multiplied by the power of 2
6> 3 means dividing 6 by the power of 2
& Operation
| Or operation
^ Exclusive or operation
First, convert the decimal integer to binary.
6 & 3 means that the corresponding positions are consistent. If the values are 1, 1 is required, and the other values are 0.
6 | 3 means that the corresponding positions are the same, as long as 1 is 1, all 0 will get 0
6 ^ 3 means that the corresponding positions are the same, the upper and lower values are the same, and the lower and lower values are 0, and the difference is 1.
110
011 & Computation
010 = 2
110
011 | or operation
111 = 7
110
011 ^ exclusive or
101 = 5
These bitwise operations can be used for encryption.
Public class VariableDemo {/*** @ param args */public static void main (String [] args) {System. out. println (6 <3); // output 48 System. out. println (6> 3); // outputs 0 System. out. println (6 & 3); // output 2 System. out. println (6 | 3); // output 7 System. out. println (6 ^ 3); // output 5 }}