For the problem of the original code anti-code complement, corresponding to the computer, the fixed-point number has 3 kinds of representations: the original code, the inverse code and the complement
The so-called original code is the binary fixed-point notation, that is, the highest bit is the sign bit, "0" is positive, "1" is negative, the remaining bits represent the size of the value.
The inverse code notation stipulates that the inverse code of a positive number is the same as its original code, and the inverse of a negative number is a bitwise negation of its original code, except for the sign bit.
The complement notation stipulates that the complement of positive numbers is the same as the original code, and that the complement of negative numbers is added to the minus 1 of the inverse code.
1, the original code, the inverse code and the complement expression method
(1) The original code: directly before the value of a symbol to add a bit of notation.
Example: Symbol bit value bit
[+7] Original = 0 0000111 B
[-7] original = 1 0000111 B
Note: A. The source code for the number 0 has two forms:
[+0] Original =00000000b [-0] Original =10000000b
B. Range of 8-bit binary source code: -127~+127
2) Anti-code:
Positive number: The inverse of the positive number is the same as the original code.
Negative number: The inverse of the negative, the sign bit is "1", the numeric part is reversed by a bit.
Example: Symbol bit value bit
[+7] anti = 0 0000111 B
[-7] anti = 1 1111000 B
Note: A. There are two types of anti-code for number 0, namely
[+0] Anti-=00000000b
[-0] anti-=11111111b
B. 8-bit binary anti-code representation range: -127~+127
3) How to express the complement
1) The concept of a module: a unit of measurement called modulus or modulus. For example, the clock is counted as a 12-based loop, which is modulo 12. On the clock, the hour hand is added (positive dial) to the integer digits of 12 or minus (reversed) 12 of the integer digits, the position of the hour hand is constant. 14 O'Clock after the Die 12, become (PM) 2 o'clock (14=14-12=2). From 0 to 10, minus 10 hours, it can also be seen from 0 points clockwise Dial 2 (plus 2 hours), that is, 2 points (0-10=-10=-10+12=2). Therefore, under the premise of modulo 12, 10 can be mapped to +2. Thus, for a circulatory system with a modulus of 12, the effect of adding 2 and minus 10 is the same; therefore, in 12-mode systems, all operations minus 10 can be replaced by the addition of two, which translates the subtraction problem into an additive problem (note: The computer's hardware structure is only adder, So most of the operations must eventually be converted to addition. 10 and 2 are complementary to modulo 12.
Similarly, the computer's operating parts and registers have a certain word length limit (assuming the word length is 8), so its operation is also a modulo operation. When the counter is full of 8 bits, which is 256 digits, an overflow is generated and counted from the beginning. The amount of overflow generated is the module of the counter, obviously, the 8-bit binary number, its modulus is 28=256. In the calculation, two complementary numbers are called "complement".
2) Complement expression: Positive number: The complement of the positive number is the same as the original code.
Negative numbers: The complement of a negative number is the sign bit is "1", the value of the part is reversed after the first (lowest bit) plus 1. That is, "anti-code +1."
Example: Symbol bit value bit
[+7] complement = 0 0000111 B
[-7] complement = 1 1111001 B
The complement is an important form of coding in a microcomputer, please note:
A. After using the complement, the subtraction operation can be easily converted into addition operation, and the operation process is simplified. A positive complement is the true value of the number it represents, and the complement of a negative number is not the truth of what it represents. The results are still in complement with the complement operation.
B. Unlike the original code, the inverse code, the value of 0 of the complement only one, that is, [0] complement =00000000b.
C. If the word length is 8 bits, then the complement is expressed in the range of -128~+127; When doing the complement operation, it should be noted that the result should not exceed the range of the number of the complement can be expressed.
Original code anti-code complement