C ++ little knowledge and little knowledge
I. The Supplementary Code is the explanation of the original code.
Assume that a negative number x is represented by an 8-bit binary number, then the complement code = 2 ^ 8-| x |, and then the complement code = 2 ^ 8-(2 ^ 8-| x |) = original code of this number
2. int value range:-2 ^ 15 ~ 2 ^ 15-1
Because the data stored in the computer is stored in the form of binary complement code, the range of the binary value of the positive number is 0000 0000 0000 0000 ~ 0111 1111 1111 1111 (0 ~ 2 ^ 15-1), the negative number range is
1000 0000 0000 0000 ~ 1111 1111 1111 1111 (it is stored as a complement, and the original code is obtained by removing the symbol bit and adding it back to 1)-2 ^ 15 ~ -1.
Iii. Reasons for using supplemental code storage on computers (transfer)
All numbers in a computer exist in binary format. Binary has multiple encoding methods in the computer, such as the original code, anti-code, and complement code. In these encoding methods, the most used is not the simplest and most direct source code, but the complement code. Why? If you want to understand the problem, you must first understand the source code, the reverse code, and the supplementary code. If you do not know much about them, let's take a look at another blog-the original code, anti-code, and re-code are actually very simple. If you are familiar with them, let's continue.
A, B, and C are similar things. C is chosen instead of A and B, so C certainly has the advantages none of the other two. So what advantages does the CAPTCHA complement have in favor of him? The following is a detailed analysis:
Original code:
The feature of the original code is that the encoding is simple and intuitive, and it is very convenient to convert to the true value. Since the source code is so good, why did you choose not to replace it? The next step is not to select the key. Although the original code is very simple and intuitive, a problem occurs when the original code is used to represent 0. 0 is represented by the original code + 0 and-0. When the machine word length is 8,
[+ 0] original = 00000000, [-0] original = 10000000.
This is a problem. The same number has two representation types, resulting in ambiguity, which makes it difficult for the machine to judge 0. The second is when the original code is used for calculation, symbol bits must be processed separately, and the calculation rules are complex. For example, in addition operation, if there are two different numbers, you must first make the number of the absolute value greater minus the number of the absolute value smaller, and then pay the symbol of the absolute value greater to the result. In addition, it is very difficult to use computer hardware for bitwise operations. It is precisely because of these shortcomings that the original code prompts people to study other coding methods.
Anti-code:
Anti-code is rarely used. Its main purpose is to serve as a bridge between the source code and the complement code. Like the original code, it has two Representation Methods for 0,
[+ 0] = 00000000, [-0] = 11111111.
The reason for not using the reverse code is similar to that of the original code.
Complement:
When it comes to code complementing, we have to introduce another concept-modulus. A module is the capacity of a metering device in the house. Here, we often give an example of a clock. Its modulus is 12, that is, every 12 is used to start from 0 again. It is called a modulo or a remainder (mod) in mathematics ), in java, C #, and C ++, % Represents the remainder operation. For example:
14% 12 = 2
If the correct time is and your watch points to, how can I adjust the table accuracy? You can use either of the following methods: A table is allocated two hours in a clockwise manner, or a table is allocated 10 hours in a clockwise manner.
8-2 = 6
(8 + 10) % 12 = 6
That is to say, in this module system
8-2 = 8 + 10
This is because 2 and 10 pairs of modulus 12 complement each other. So there is A conclusion: In A modulus system, A-B or A + (-B) is equivalent to A + [B fill], that is
8-2/8 + (-2) = 8 + 10
We call 10-2 The complement code under mod 12. In this way, the negative number can be expressed by the complement code, and the addition and subtraction can be unified into addition to simplify the complexity of the operation.
There are two advantages of using the complement code for computation. One is the unified addition and subtraction mentioned earlier. The other is to allow the symbol bit to directly participate in the computation as a value, and finally get the correct result operator.