The original code, the inverse code, the complement 1 in binary system. 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 first bit is the sign bit. Because the first bit is the sign bit, the range of values for the 8-bit binary number is:
[1111 1111, 0111 1111]
That
[-127, 127]
The original code is the most easily understood and calculated representation of the human brain.
2. Anti-code
The inverse code is represented by:
The inverse of a positive number is its own
Negative number of the inverse code is on the basis of its original code, the sign bit is unchanged, the remaining bits are 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.
3. Complement
The complement is expressed in the following ways:
A positive complement is its own
The complement of a negative number is on the basis of its original code, the sign bit is 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.
For a signed number:
(1) The highest bit of binary is the sign bit: 0 for positive, 1 for negative
(2) Positive number of the original code, anti-code, and complement are the same;
(3) Negative number of the inverse code = Its original code sign bit unchanged, the other bits take the reverse (0->1; 1->0);
(4) The complement of negative number = its inverse code +1;
(5) 0 of the anti-code, the complement is 0;
(6) In the computer operation, are in the way of the complement of the calculation;
Example:
Let's use "signed number" to simulate how the computer is computed.
(1) Sum of positive numbers:
For example, the operation of the computer is as follows:
1 of the original code is:
00000000 00000000 00000000 00000001
Because "positive number of the original code, anti-code, and complement are the same", so, 1 of the complement = 1 of the original code, so 1 of the complement + 1 of the complement is equal to:
00000000 00000000 00000000 00000001
+
00000000 00000000 00000000 00000001
=
00000000 00000000 00000000 00000010
00000000 00000000 00000000 00000010 (converted to 10 binary) = 0*2^0 + 1*2^1 = 0 + 2 =2
(2) Positive subtraction:
For example: 1-2, the operation of the computer is as follows:
The subtraction operation in the computer is actually operated as an add operation, so, 1-2 = 1 + (-2)
The first step: to find out the 1 complement (because the positive number of the original code, anti-code, and complement are the same, so we can get the complement directly from the original code):
1 of the complement:
00000000 00000000 00000000 00000001
The second step: 2 of the original code to find out:
-2 of the original code:
10000000 00000000 00000000 00000010
The third step: 2 of the anti-code to find out:
-2 of the anti-code:
11111111 11111111 11111111 11111101
Step three: Find out the 2 complement:
-2 of the complement:
11111111 11111111 11111111 11111110
The fourth step: the complement of 1 and the complement of-2:
00000000 00000000 00000000 00000001
+
11111111 11111111 11111111 11111110
=
11111111 11111111 11111111 11111111
Fifth step: The result of the calculation of the complement to the original code, the opposite can be (if you want to convert binary to decimal, you must get the binary source code)
Complement: 11111111 11111111 11111111 11111111
=
Reverse code: 11111111 11111111 11111111 11111110
=
Original code: 10000000 00000000 00000000 00000001
Sixth step: Convert the binary source code of the calculation result to decimal
Binary source code: 10000000 00000000 00000000 00000001 = 1*2^0 = 1
---------------------This article from Realnewdream csdn blog, full-text address please click: 17333743?utm_source=copy
The inverse code complement of the original code in binary