Leisure origin, back code, complement
I believe that everyone will see this title, because there is their explanation in the first chapter of any computer basic knowledge, but we can only find some simple definitions in the book, and after seeing it, forget. Recently, some people asked these concepts. Seeing that many people's reply was to have seen it now forgetting to see a certain book, very little explanation. So I started thinking (although God will laugh, I still have to think.), So I got the following conclusions.
The value is in the computer to represent the number of machines. Computers can only identify 0 and 1, and use binary, and people in daily life are ten into systems. "As Aristotle pointed out, today's decimal Widely adopted, only the most of our lives have a result of 10 anatomical facts of 10 fingers. Although the practice of finger count (5, 10) is more than two or three-input counts in history. "(Excerpted from << Mathematics Development History >> Have a space, you can see it ~, very interesting). In order to be convenient and binary conversion, he uses hexadecimal (2
4
) And eight-based (2
3
The following is the topic.
The value has a positive and negative points, the computer uses the highest bit storage symbol (0 is positive, 1 is negative). This is the original code of the machine number. Assume that the number of bits that the machine can process is 8. ie the word length 1byte, the original code can indicate the range of values
(-127 ~ -0 0 ~ 127) a total of 256.
With a numerical representation, you can count the arithmetic operation. But soon, I found that the results were correct when using the original code of the symbolic bit, and there was a problem when the addition and decrease was calculated, as follows: hypothesis: 8bits
(1) 10- (1) 10 = (1) 10 (-1) 10 = (0) 10
(00000001) Original (10000001) Original = (10000010) Original = (-2) obviously incorrect.
Because there is no problem in the two integers of the addition, it is found that there is a negative number of symbolic positions, and the remaining points of the symbol are produced inversely. The value of the inverse code The space and the original code are the same and one by one. The following is the subtraction operation:
(1) 10 - (1) 10 = (1) 10 (-1) 10 = (0) 10
(00000001) Anti- (11111110) Anti-= (11111111) anti- = (-0)
has a problem.
(1) 10 - (2) 10 = (1) 10 (-2) 10 = (-1) 10
(00000001) Anti- (11111101) anti- = (11111110) anti- = (-1) correct
The problem appears in ( 0) and (-0), zero is no positive and negative in people's calculation concept. (Indians first use zero as marked and put into operations, including zero-based India Mathematics and decimal counts have great contribution to human civilization).
So I introduced the complement concept. The decoding of negative numbers is to add one, and the positive number is unchanged, the positive original code is the same. In the completion of the completion (-128) instead ( -0), so the scope of complement is:
(-128 ~ 0 ~ 127) a total of 256.
Note: (- 128) There is no corresponding original code and counter code, (-128) = (10000000)
The addition and subtraction of the complement is as follows:
(1) 10- (1) 10 = (1) 10 (-1) 10 = (0) 10
(00000001) Complete (11111111) = (00000000) Mix = (0) correct
(1) 10- (2) 10 = (1) 10 (-2) 10 = (-1) 10
(00000001) Supplement (11111110) to make up = (1111111) to make up = (-1)
correct
So the design purpose of the complement is:
(1) Simplification of the calculation rules together with the symbol bit can participate in the calculation with the valid value section.
(2) Make subtraction operations into an additional operation, further simplify the line design of the computer in the computer, all of these conversions are carried out at the bottom of the computer, and in other high-level languages of the compilation, C, etc. are original code . After reading these, everyone should have a new code, back code, and complement,!