1 arithmetic operators: +,-, *,/,%2 self-increment: + +,--3 assignment operator: =, +=,-=,*=,/=4 relational operator: >,<,>=,<=,==,! =
Logical operators: &, | ,! ,&&, | |
Bitwise operator: It is calculated on bits.
A bitwise operator is a decimal integer that can be computed by converting decimal into binary.
The binary consists of 0 and 1, so the result of the calculation is either 0 or 1
Symbols for 1.5-bit operators:
& (with): Both are 1 when I am one, the others are 0
| (OR): Both are 0 o'clock to 0, and the others are 1.
^ (XOR): The difference between the two is 1, the same as 0
~ (Inverse): 0 becomes 1, 1 becomes 0.
The representation of negative numbers: the highest bit of bits is 1, then this number is a negative.
1111-1111 1111-1111 1111-1111 1111-1111:-1
0000 0000 0000 0000 0000 0000 0000 0000:0
-2:1111-1111 1111-1111 1111-1111 1111-1110
-3:1111-1111 1111-1111 1111-1111 1111-1101
-4:1111-1111 1111-1111 1111-1111 1111-1100
-5:1111-1111 1111-1111 1111-1111 1111-1011
-6:1111-1111 1111-1111 1111-1111 1111-1010
-7:1111-1111 1111-1111 1111-1111 1111-1001
0000-0000 0000-0000 0000-0000 0000-0111 = 7
1111-1111 1111-1111 1111-1111 1111-1001
Rule: Negative number corresponding to the positive number-1, take the inverse
Negative number corresponding to the positive negation +1
Role: Data is encrypted
123456
0-100 A-Z
24845845957512317580960--->123456
6 shift Operator: operation on Bits
6.1 >> Right Shift
6.2 << Left Shift
6.3 >>> Unsigned Right shift
>> Right Shift
<< left Shift
>>> Unsigned Right Shift
Move right:
System.out.println (6>>1); --->3 6/2 2*1
System.out.println (6>>2); --->1 6/4 2*2
System.out.println (6>>3); --->0 6/8 2*3
System.out.println (6>>4);
System.out.println (9>>1); --->4 9/2 2*1
System.out.println (9>>2); --->2 9/4 2*2
System.out.println (9>>3); --->1 9/8 2*3
System.out.println (9>>4);//--->0 9/16
System.out.println ( -6>>1); -6/2-->-3
Rule: Shift the number of digits to the right by dividing by 2 how many times you need to move.
Move Left:
SYSTEM.OUT.PRINTLN ("-----This is the result of the left Shift----------");
System.out.println (6<<1); --->12 6*2 2*1
System.out.println (6<<2); --->24 6*4 2*2
System.out.println (6<<3); --->48 6*8 2*2*2
System.out.println (6<<4); ---->96 6*16 2*2*2*2
System.out.println ( -6<<2);//--->-24
Rule: How many digits to the left, multiply this number by 2 times.
>>> Unsigned Right Shift
System.out.println (6>>>1); 3
System.out.println (6>>>2); 1
System.out.println ( -6>>>2); 1073741822
Principle: See picture.
Function: Increase the operation rate. Bit arithmetic is the fastest execution.
For example: Calculate 2*8 in the quickest way
2<<3 = = 2*8 = 16
Features: A number A and two the same number ^, the final result is still the original number A.
Operators in Java