Reference article:
(a very good article, it is strongly recommended to see this article)
https://blog.csdn.net/zl10086111/article/details/80907428
Before learning the original code, anti-code and complement, the number of machines needed to understand the concept and the true value.
- Encoding: binary number representation in a computer, this number is called the machine number. Machine number is signed, in a computer with a number of sign bits to store the most positive number of 0, a negative number.
- True: the number of machines with a sign bit corresponding to the real value, called the true value of the number of machines.
Example: true value = 0000 0001 +000 0001 + 1 =
Original code
Original code is the sign bit plus the absolute value of the true value, i.e., a symbol represented by a first, a value representing the remaining bits. For example, if 8-bit binary.
[L] = the original 0000 0001
[-1] = 1000 0001 Original
first one because the first bit is the sign bit is the sign bit, so the range is 8-bit binary numbers:
[11111111, 01111111]
i.e. (128-1)
[-127, 127]
Inverted
Positive constant
negative sign bit unchanged, remaining negated
Complement
Positive constant
negative to a plus-minus
EG
[+ 1'd] = [00000001] Original = [00000001] trans = [00000001] up
[-1] = [10000001] Original = [11111110] trans = [11111111] Complement
Anti-code and complement the role of
- In order for computer operation easier, the subtraction operation into a negative increase, so the introduction of the inverted
EG:
. 1 -. 1. 1 = + (-1) = [0000 0001] Original + [1000 0001] Original = [0000 0001 ] + anti [11111110] trans = [1111 1111] trans = [1000 0000] = -0 original
The only problem 2. anti-code in fact appear on "0" this special value. Although people understand the +0 and -0 is the same, but with 0 symbol is no sense. And there will be [0000 0000] primary and [1000 0000] 0.5 represents the original two's complement encoding solve this problem
EG:
1-1 of =. 1 + (-1) = [0000 0001] original + [1000 0001] original = [0000 0001] complement + [1111 1111] complement = [0000 0000] complement = [0000 0000] original
Such is represented by 0 [0000 0000], and -0 problems existed previously but not with [10000000] -128 represents:
(-1) + (-127) = [1000 0001] Original + [1111 1111] original = [1111 1111] complement + [1000 0001] complement = [1000 0000] complement
which is why the 8-bit binary, the range of use of the original code or anti-code representation is [-127, +127], the use of complement range represented by [-128, 127].