Operator Category:
According to the number of operands
Monocular a ++
A + b binocular
? Trinocular (a> b) x: y
Classified by operators
Arithmetic
Plus minus + - * except multiply / modulo% increment decrement ++ -
you x = 1 ; you y = x ++;
Results x = 2; y = 1;
After the first assignment when calculating arithmetic operation, after the first x ++ backup computing, to put their values into temporary space, then their + 1, after the value of the temporary space will be credited y.
you x = 1 ; you y = x ++;
Results x = 2; y = 2;
After the first assignment when calculating arithmetic operation, ++ x calculated after the first backup, the value of their own +1, then stored in the temporary space, after the value of the temporary space will be credited y.
therefore:
int x = 1; x = x++;
Results x = 1;
x ++ to back the calculated values are stored in the temporary space itself and its own +1 (x = 2), then the value will be stored in temporary space x (x = 1).
int m = 1; int n = 2; int sum = m++ + ++n - n-- - --m + n-- - --m;
sum = 1 + 2 - 3 - 1 + 2 - 0 = 2;
m = 2, n = 2, sum = 1;
m 、= 2, n = 3, sum = 1 + 3 = 4;
m = 2, n = 2, sum = 4 - 3 = 1;
m = 1, n = 2, sum = 1 - 1 = 0;
m = 1, n = 1, sum = 0 + 2 = 2;
m = 0, n = 1, sum = 2 - 0 = 2;
Assignment Operators
= Sign, plus + = equal, equal to minus - =, * = multiplication equal, except at / =,% = equivalent mold
int x += 10;
Equivalent x = x + 10; but this is a copy operation, no arithmetic operation. and so
byte x = 1; x += 1; x = x + 1;
x + = 1 is not given, the assignment operator automatically converted;
x = x +1 will complain, because x is a byte, 1 is an int, the calculation will be problems.
Relationship (comparison) operation
Greater than> greater than or equal to> = Less than <, less than or equal to <=, not equal! =, == equal, comprising at instanceof
It is true or false;
3 > 2 true
3 < 2 false
logic operation
And logic &, logical or |, ^ exclusive OR, logical negation, shorted &&, ||, or short circuit;!
Connecting boolean result;
&: Before and after are true, the result is true
|: Before and after at least one is true, the result is true
^: A before and after is true, one is false, the result is true
!: True and false conversion. The results negated
&&: front and rear are both true, the result is true, if the foregoing is false, the direct output false, the latter is no longer calculated. In front is true can improve efficiency
||: at least one of the front and rear is true, the result is true, if the foregoing is true, the direct output true, the latter is no longer calculated. In the back is true can improve efficiency
Bit operation (bit)
Bitwise AND &, | bitwise or, bitwise exclusive OR ^, ~ bitwise
<< Bitwise left shift, right shift >> Bitwise, >>> Bitwise right shift (unsigned)
Used to calculate the binary.
10 is converted to binary decimal
2 in addition to taking the remainder, to take significant bit reverse order
60
30 0
15 0
7 1
3 1
1 1
0 1
Flashback can get 111100
The 60--> 111100;
3&5
3 and 5 becomes the binary, and then ANDed with each
00000000 00000000 00000000 00000011
00000000 00000000 00000000 00000101
-------------------------------------------------- ------ op
00000000 00000000 00000000 00000001
And then converted to decimal,
3&5 = 1
Similarly available
3|5 = 111 = 7
3^5 = 110 = 6
~ Converted to 2's complement and then negated
1-6 = -7; complement inversion 00000000 00000000 0,000,000,000,000,110 -> 1,111,111,111,111,111 1,111,111,111,111,001 sign bit is one, the number is negative, subtract one negative sign inversion 00000000 00000000 0,000,000,000,000,111 6 = 7 = -7 so ~ ;
= -6 ~ 5; complement inversion 1,111,111,111,111,111 1,111,111,111,111,010 -> 00000000 00000000 0,000,000,000,000,101 = 5;
A computing is negated, all of the source can be negated. Anti-code is a code, different from both.
Source code, anti-code complement:
Positive anti-code case, consistent and complement source, a negative sign bit inverted to maintain constant bit inverse of the other, is the inverted complement +1; complement code into the source code needs to -1, then negated, or then negated +1
Digital storage computer's complement form.
6 -6
Source 00000000 00000000 0,000,000,000,000,110 1,000,000,000,000,000 0,000,000,000,000,110
Anti-code 00000000 00000000 0,000,000,000,000,110 1,111,111,111,111,111 1,111,111,111,111,001
Complement 00000000 00000000 0,000,000,000,000,110 1,111,111,111,111,111 1,111,111,111,111,010
Complement 6 << x = 00000000 00000000 00000000 00000110 moves to the left the value of x bits, equivalent to a multiplication of 2 raised to the power x
6 << 2 = 00000000 00000000 00000000 00011000 = 16 + 8 = 24
Similarly
6 >> 1 = 00000000 00000000 0,000,000,000,000,011 = 3; complement value of x moved to the right position, corresponding to the power of x divided by 2, is consistent with the sign bit source, n is 0, 1 negative
6 >> 2 = 1;
-6 >> 1
-6 complement: 1,111,111,111,111,111 1,111,111,111,111,010
After right: 1,111,111,111,111,111 1,111,111,111,111,101
It becomes Source: 1,000,000,000,000,000 0,000,000,000,000,011 = -3
-6 >> 1 = -3
>>> unsigned right shift, the sign bit is 0 after the mobile
-6 >>> 1
-6 complement: 1,111,111,111,111,111 1,111,111,111,111,010
After right: 0,111,111,111,111,111 1,111,111,111,111,101
Changes to the source code (the so become positive and complement the same source): 0,111,111,111,111,111 1,111,111,111,111,101
Octal beginning with 0
Beginning with 0X hexadecimal.