Tag: Take reverse XOR HashMap bitwise negation now absolute amp unsigned
Although Java's bitwise operators are seldom used in daily life, it is found that there are >>> operators in the source code of HashMap, and also the bit operations in Java are learned by the way.
First, & and bitwise AND, if the same bit of two binary numbers is 1, then the new binary number obtained is also 1, otherwise 0;
| or bitwise OR, if the two binary numbers have the same bit at least one of 1, then the new binary number obtained is the bit also 1, otherwise 0;
^ XOR Bitwise XOR, if the two binary numbers are the same bit different (one for 11 is 0), then the new binary number obtained is the bit 1, otherwise 0;
~ Not non, with the above three is different: the above is two number bitwise operation to get a new number, ~ is a binary number bitwise negation.
Second, >>, >>> and << shift operators
>> and >>> are right-shift operators, the difference is that >> is signed right shift,>>> number unsigned right shift.
If the number is positive, after the right shift >> and >>> are in the high 0, there is no difference, if the number is negative, after the right shift >> in the high-fill 1,>>> in the high-fill 0.
<< is the left-shift operator.
The number following the symbol indicates the number of bits moved.
Third, add: Original code, anti-code and complement.
The original code, the inverse code and the complement of the positive numbers are the second binary representations;
Negative Number: The original code is the absolute value of the binary representation, and then the sign bit is 1, the anti-code for the sign bit counter, the complement is anti-code plus 1.
The numbers are stored in the form of a complement in the computer.
bitwise operators in Java