The original code, the inverse code, the complement is the Java Numerical Operation Foundation, in the computer program, the numerical operation is based on the binary system, namely the bottom layer is the binary operation. And the value has positive and negative numbers, binary only 0 and 1, how to represent negative numbers, how to do positive and negative operations, this is the meaning of the original reverse.
Base definition: * Original code* is the binary fixed-point notation, that is, the highest bit is the sign bit, "0" means positive, "1" is negative, and the remaining bits represent the size of the value. * Through a byte, that is, 8 bits means +7 and -7* 0 (sign bit) 0000111 * 1 (sign bit) 0000111 * Anti-code* The inverse of a positive number is the same as its original code; the inverse of a negative number is a bitwise negation of its original code, except for the sign bit. * Complement The complement of positive numbers is the same as the original code, and the complement of negative numbers is added to the minus 1 of the inverse code. In the process of symbolic numerical operation, the operation is based on the complement, so, to be complementary is to clarify the fundamental of symbolic operation. Case: -4+3:3 binary: 0 (sign bit) 0000011 (source) 0 &NB SP; (sign bit) 0000011 (reverse code) 0 (sign bit) 0000011 (complement)-4 binary: 1 (sign bit) 0000100 (source) &NB Sp 1 (sign bit) 1111011 (anti-code) & nbsp 1 (sign bit) 1111100 (complement) 0 (sign bit) 0000011 (complement) + 1 (sign bit) 1111100 (complement) --------------------------------------- ---- 1 (sign bit) 1111111 (complement)- 1------------------------------------------- 1 (sign bit) 1111110 (anti-code) take anti-------------------------------------------- 1 (sign bit) 0000001 (original code) Turn 10 into 1, which is the result of the calculation . in Java, except in the signedThe original inverse complement is used in numerical operations, and is also useful in the forced type conversion of the data, for example:
byte a = (byte) 300; // the range of byte is -128~127, and 300 is more than the one that needs to be cast.
300 binary forms are: 00000000 00000000 00000001 00101100
After the cast (intercept) is: 00101100//At this time the complement form
At this point the highest sign bit is 0, which is a positive number, and the original inverse of the positive is the same, so the last value of a is 44;
The first writing, the haphazard, some omissions, Wan Wang pointed out.
Java's original reverse complement