The original code: sign bit with 0 for the positive sign, with 1 for the minus, the value is generally used in binary form to represent the inverse code: Machine number of the inverse code can be obtained from the original code. If the number of machines is positive, then the inverse code of the machine number is the same as the original code, if the number of machines is negative, then the counter code of the number of the machine is the original code (except for the sign bit) you get. Complement: The complement of the machine number can be obtained from the original code. If the number of machines is positive, then the number of the machine is the same as the original code, if the number of machines is negative, then the number of the machine is the complement of its original code (except for the sign bit) to take the inverse, and in no place plus 1 to get. Positive number: Original code= anti-code =the complement is expressed in the original code; negative: Anti-code=~ original code (except sign bit), complement = anti-code +1, expressed in the complement of a System.out.println (integer.tobinarystring), for example:-5) ); Print:1111 1111 1111 1111 1111 1111 1111 1011don't think about it. The 32-bit process is this: a negative number, such as-5, it's binary in the inside is like this expression1000 0000 0000 0000 0000 0000 0000 0101the positive value of this is:0000 0000 0000 0000 0000 0000 0000 0101The inverse code is:1111 1111 1111 1111 1111 1111 1111 1010plus 1 is:1111 1111 1111 1111 1111 1111 1111 1011the content that gets printed~operator, the content of each bits is reversed, that is, 1 becomes 0, 0 becomes 1 test negative:intA =-5;//101;SYSTEM.OUT.PRINTLN (~a); Print:4The process is like this, first representing the negative number1111 1111 1111 1111 1111 1111 1111 1011(The above mentioned why this is said) you have to take the reverse0000 0000 0000 0000 0000 0000 0000 0100To 10 binary to get 4 test positive:intA = 5;//101;SYSTEM.OUT.PRINTLN (~a); Print:-6first, this positive number is shown:0000 0000 0000 0000 0000 0000 0000 0101you have to take the reverse:1111 1111 1111 1111 1111 1111 1111 1010That 's what this represents.-6, as for why look at the top&operator, the corresponding bits and operation, two are 1 is 1, the other case is 0 test: System.out.println (5&6); Print:4procedure: 5 is represented as:0000 0000 0000 0000 0000 0000 0000 01016 is represented as:0000 0000 0000 0000 0000 0000 0000 0110make&: 0000 0000 0000 0000 0000 0000 0000 0100Get:4|operator, the corresponding bits is performed or manipulated, two are 0 for 0, others are 1 tests: System.out.println (5|6); Print:7procedure: 5 is represented as:0000 0000 0000 0000 0000 0000 0000 01016 is represented as:0000 0000 0000 0000 0000 0000 0000 0110make| : 0000 0000 0000 0000 0000 0000 0000 0111Get:7^operator when the corresponding bits value is the same, the bit is 0 otherwise 1 test: System.out.println (5^6); Print:3procedure: 5 is represented as:0000 0000 0000 0000 0000 0000 0000 01016 is represented as:0000 0000 0000 0000 0000 0000 0000 0110make^: 0000 0000 0000 0000 0000 0000 0000 0011Get:3<<operator, move left, fill right 0 test: System.out.println (5<<1); Print:105 is represented as:0000 0000 0000 0000 0000 0000 0000 0101make<<1 operation: 0000 0000 0000 0000 0000 0000 0000 1010>>operator, arithmetic right shift, positive left padding 0, negative left 1 test: System.out.println (5>>1); Print:25 is represented as:0000 0000 0000 0000 0000 0000 0000 0101make>>1 operation: 0000 0000 0000 0000 0000 0000 0000 0010System.out.println (-5>>1); Print:-3-5:1111 1111 1111 1111 1111 1111 1111 1011make>>1 operation: 1111 1111 1111 1111 1111 1111 1111 1101>>>operator, unsigned arithmetic right shift, left 0 test: System.out.println (5>>>1); Print:25 is represented as:0000 0000 0000 0000 0000 0000 0000 0101make>>1 operation: 0000 0000 0000 0000 0000 0000 0000 0010System.out.println (-5>>>1); Print:2147483645-5 representation: 1111 1111 1111 1111 1111 1111 1111 1101make>>1 operation: 0111 1111 1111 1111 1111 1111 1111 1101
Java Special operators (GO)