1. Interview questions
(1) Short s=1;s=s+1;
(2) Short s=1;s+=1;
There is no problem with the above two lines of code, if so, where is the problem?
A: The first problem, s+1 is the value of int type, assigned to short s, compile error;
The second s+=1 is not equivalent to s=s+1; it is equivalent to s= (the data type of s) (S+1), which has a casting process.
2, ^ (XOR) Characteristics: One data to another data bit XOR or two times, the number itself is unchanged
For example: int a=10;int b=20;
a^b^b=10;a^b^a=20;
Based on this feature, an application of ^ is able to do a simple data encryption.
Interview question: Exchange the value of a and B with an XOR operator.
A=a^b;
B=a^b;//b=a^b^b=a;
A=a^b;//a=a^b^a=b;
3, <<: Left to the left highest bit discarded, 0 on the right
>>: The right shift is 0, the left side is 0, the highest is 1, the left side is 1
>>>: Unsigned right shift whether the highest bit is 0 or 1, the left side is 0
Example:24>>2=6;
24>>>2=6;
-24>>2=-6;
-24>>>2=1073741818;
day03 Java Basics