I. Definition 1. Original code The positive sign bit is 0, and the negative sign bit is 1. The other bits represent the absolute value of the number according to the general method. In this way, the original code of the number is obtained. [Example 2.13] when the machine word length is 8-bit binary: X = + 1011011 [x] source code = 01011011 Y = + 1011011 [y] source code = 11011011 [+ 1] origin code = 00000001 [-1] source code = 10000001 [+ 127] source code = 01111111 [-127] source code = 11111111 The integer range indicated by the original code is: -(2n-1-1 )~ + (2n-1-1), where N is the machine length. Then: The Integer Range of the 8-bit binary original code is-127 ~ + 127 The 16-bit binary original code represents an integer ranging from-32767 ~ + 32767 2. Anti-code
For a signed number, the positive anticode is the same as the original code, and the negative number is the inverse of the original code except the symbol bit. [Example 2.14] when the machine word length is 8-bit binary:
X = + 1011011 [x] source code = 01011011 [X] Anti-code = 01011011 Y =-1011011 [y] source code = 11011011 [Y] Anti-code = 10100100 [+ 1] Anti-code = 00000001 [-1] Anti-code = 11111110 [+ 127] Anti-code = 01111111 [-127] Anti-code = 10000000 There is a big difference between negative and negative original codes. The reverse code is usually used as an intermediate form in the process of completing the code. The range of integers indicated by the anticode is the same as that of the original code. 3. Complement The positive complement is the same as the original one, and the negative complement is equal to the reverse code plus 1 in the trim. After the completion code is introduced, addition and subtraction operations in the computer can all be converted into addition operations for the completion code, and the symbol bit is also involved in the operation. [Example 2.15] (1) x = + 1011011 (2) Y =-1011011 (1) As defined: [x] source code = 01011011 [x] completion code = 01011011 (2) definitions: [Y] source code = 11011011 [y] Anti-code = 10100100 [Y] completion code = 10100101 The integer range indicated by the complement code is-2n-1 ~ + (2n-1-1), where N is the machine length. Then: the integer range indicated by the 8-bit binary complement code is-128 ~ + 127 (-128) The value is 10000000, and no corresponding source code or reverse code is displayed)
The 16-bit binary complement represents an integer ranging from-32768 ~ + 32767 When the calculation result is out of this range, it cannot represent the number correctly. This is called overflow. 4. Conversion Between the complement code and the true value
The true value of a positive complement code is equal to the complement Code itself. When a negative complement code is converted to its true value, the negative complement code is reversed by bit and 1 is added to the last digit to obtain the absolute value of the true value corresponding to the negative complement code. [Example 2.16] [x] fill code = 01011001b, [x] fill code = 11011001b, and calculate the true value x respectively. (1) [x] The complement represents a positive number, and its true value is: X = + 1011001b = + (1x26 + 1x24 + 1x23 + 1x20) = + (64 + 16 + 8 + 1) = + (89) d (2) If the [x] complement represents a negative number, the true value is: X =-([1, 1011001] Reverse lookup + 1) B =-(0100110 + 1) B =-(0100111) B =-(1x25 + 1x22 + 1x21 + 1x20) =-(32 + 4 + 2 + 1) =-(39) d Ii. Rules for code addition and subtraction 1. Operation Rules [X + y] fill = [x] fill + [Y] fill [X-Y] fill = [x] fill + [-y] fill If the [y] population is known, the [-y] population method is to take the [y] population (including the symbol bit) Bit by bit and then add 1 in the trim bit. For example, [y] fill = 101101 [-y] fill = 010011 2. Overflow judgment. Generally, dual-symbol bit is used for judgment: Symbol bit 00 indicates positive number 11 Negative number When the result is 01, it is called overflow; when it is 10, it is called underflow. Example: set X = 0.1101, y =-0.0111, And the symbol bit is double sign bit Returns X + Y and x-y by using the complement code.
[X] fill + [y] fill = 00 1101 + 11 1001 = 00 0110 [X-y] fill = [x] fill + [-y] fill = 00 1101 + 00 0111 = 01 0100 Incorrect result, positive Overflow |