After taking part in the soft test, the first contact with the knowledge of computer system, its main introduction of the structure of computers, as well as the principle of computer, are some very abstract things.
We all know that the computing in the computer is done by binary, but because there are only addition operators in the computer, it is often wrong to do the subtraction operation, which also requires us to convert the subtraction operation to the addition operation. So there are various codes.
1, the original code
The original code is the absolute value of the symbolic bit plus the truth, that is, the first digit represents the symbol, and the remaining bits represent the values. For example, if it is a 8-bit binary:
[+1] original = 0000 0001
[-1] original = 1000 0001
The original code is the most easily understood and calculated representation of the human brain.
2, anti-code The inverse code is represented by: positive inverse code is its own, negative number of the inverse code is in its original code base, the sign bit is unchanged, the rest of each bit is reversed.
[+1] = [00000001] original = [00000001] Reverse
[-1] = [10000001] original = [11111110] Reverse
It can be seen that if an inverse code represents a negative number, the human brain cannot visually see its value. It is usually converted to the original code and then calculated.
Inverse code: Solve the problem of negative addition operation, the subtraction operation is converted to addition operation, thus simplifying the operation rules;
3. Complement The complement of the expression method is: Positive complement is its own, negative complement is in its original code on the basis of the symbol bit unchanged, the rest of you take the counter, the last +1. (That is, on the basis of the anti-code +1)
[+1] = [00000001] original = [00000001] counter = [00000001] Complement
[-1] = [10000001] original = [11111110] counter = [11111111] Complement
for negative numbers, the complement representation is also the human brain can not intuitively see its value. It is also often necessary to convert the original code to calculate its value.
PS: Another convenient way to convert the original code to a complement: the numerical part from the low to high-level search, the first 1 and the right of each of you 0 to remain unchanged, the first 1 to the left of the people to reverse.
complement: solve the negative addition operation plus or minus 0 problem, make up the lack of anti-code.
4. Shift Code
Shift Code representation: No matter positive negative number, as long as its complement of the symbol bit to reverse.
[+1 ] = [00000001] original = [00000001] anti = [00000001] complement =[10000001] Shift
[-1] = [10000001] original = [11111110] anti = [11111111] complement =[01111111] Shift
Summary:
1, positive number of the original code, complement, anti-code are its own;
2, negative (binary) of the original code, complement, anti-code formula:
Inverse code = original code (except for the sign bit) each bit is reversed
complement = anti-code + 1
Anti-code = complement-1
Shift code = complement symbol position inversion
3, the binary number, two number of the sum of the complement equals two number and the complement.
Soft Test road--the world of yards