Original-128 binary has the original code anti-code and complement code

Source: Internet
Author: User

Transferred from:

Http://kb.cnblogs.com/a/1450313/

 

First Revision

---------------------
1. Concept of Modulo (I will only give an example to illustrate how to look up the concept of "same-modulus" in mathematics ")
In daily life, there are many examples of subtraction and addition. For example, the clock runs at 12 bits, and can also be regarded as zero.
There are two ways to adjust the hour hand from 10 to 5:
1. Set the clockwise direction to 5 cells, which is equivalent to subtraction: 10-5 = 5
2. Dial 7 cells clockwise, equivalent to addition: 10 + (12-5) = 12 + 5 = 5 (12)

2. Use of the modulo (using the modulo to obtain the complement code)
1. the following code is obtained: It is used to change a negative number to a positive number that can be added. So, the complement code of a negative number = the absolute value of a negative number.
For example,-1 Completion code: 1111 1111 (10000 0000-1)
When a number is reduced by 1, you can directly add 1111 1111
2. Original Code :( The original code of a negative number. Change the maximum digit corresponding to a positive number to 1. )
The original code can intuitively represent a negative number (the true value can be intuitively displayed, for example,-1 is 1000 0001
The highest bit indicates the symbol bit, and no arithmetic computation is performed)
3. Conclusion: The code is added and discarded only after 9th bits (Model 10000 0000)
Add the original code to 8th bits (Modulo 1000)
Add back code, discard to 8th bits (mod 1000 0000)
3. Conversion between the source code and the supplemental code:
1. complement = reduce the original code by 1, and then reverse (easy to understand)
Or Complement = reverse code + 1 (Easy description and reasoning)
2. Demo: complement = reduce the original code by 1, and then reverse
For example, if the source code of-1 is 1000 0001 --> 1000 0000 1111 (after 1 is subtracted) --> 1111 (after reverse retrieval)
3. Demo: complement = reverse code + 1)
For example, the original code of-1 is 1000 0001 --> 1111 1110 (reverse code) --> 1111 1111 (plus 1 ).
4. Key points: (especially when carrying data)
The highest bitwise of the source code and the anticode is the sign bit. It does not participate in arithmetic operations. The modulo is 1000 0000 (0 Less Than the complement code)
All the bits of the complement code can be added, and the modulo is 10000 0000 (the highest bit is not a sign bit, And the complement code is obtained by subtracting the absolute value of the negative number)
5. Inference-128 of the original code and complement code (with complement = anti-code + 1)
1. For the original code 1000 0000, is it-0 or-128? (The answer is-128 instead of-0)
1. First, let's look at the concept of the original code: the sign bit of a positive number is 0, the sign bit of a negative number is 1, and the other bits represent the absolute value of the number according to the general method.
2.0 is negative? If 0 is neither a positive nor a negative number, is its symbol bit 0 or 1? (0 signs are 0, and cannot be 1)
3. Let's look at the formula for the negative complement: the complement of the negative number = 10000 0000 (Modulo)-the absolute value of the number
For example:-1 1111 1111 = 10000 0000-0000 0001
-2 1111 1110 = 10000 0000-0000 0010
If-0 is a negative number
-0 of the complement code should be 10000 0000-0 (this 0, let's teach the absolute value of 0) = 0000 0000
Reverse code: 1111 1111 0000 (0000 0000-1 = 0000 1111 + 1111 1111 = 1111)
Original code: 1000 0000
Now let's push-128
-128 completion code: 10000 0000-1000 0000 (+ 128 without a symbol) = 1000 0000
Anti-code: 1111 1111 1000 (0000 1000-1 = 0000 1111 + 1111 1111 = 1111) (complement-1)
Original code: 1000 0000 (reverse code)
From the above, an original Code corresponds to two complement codes.
But careful analysis: the concept of the original code, the negative number of the symbol bit is 1, but 0 is not a negative number, so this formula cannot be used
0 is not a positive number, but 0 can be defined as the original code, anti-code, and complement code (that is, 0000 0000)
In addition, it is said that there is only one complement code for 0. (If you are interested, you can push it)
Now the original code 1000 0000 is uniquely represented as-128 instead of-0, because-0 cannot be calculated using this formula.
Now, if the source code of 1000 0000 is 1000 0000 (proved), is the source code of 1000 0000 1000 0000?
Original code 1000 0000 (-128, carry rounded off)
Reverse Code 1111 1111
The complement code is 1000 0000 (1111 1111 (reverse code) + 1 = 1000 0000 1111. Here we actually add the seven digits after 1111,
The 1st bits are the symbols that will never change. Therefore, when the number reaches the 8th bits, it indicates overflow and will be discarded)
2. To sum up, the complement Code of 1.-128 is 1000 0000 as the original code,
2.0 of the original code, reverse code, and complement code are the same (that is, 0000 0000)
3. If-0 is treated as a negative number, 1000 0000 will be ambiguous (in fact, only one 0000 complement code of 0 is used)

 

First manuscript

-----------------
1. Meaning of using the reverse code:
1. Enable the symbol bit to join the operation with the valid value to simplify the operation rules. This simplifies the structure of the generator and increases the computing speed;
(Subtraction can be expressed by addition .)
2. addition operations are easier to implement than subtraction operations. Converts the subtraction operation to addition, further simplifying the line design of the calculator in the computer.
2. the binary number string of a negative number usually uses the complement Code: (how to push the complement code through the original code,Especially-128 )
1. Three principles are given first. :
1. Because the complement code can be used to process the signed bits and other bits in a unified manner, the subtraction can also be processed by addition, that is, if it is the number indicated by the complement code,
Addition and subtraction can be implemented directly by addition and subtraction.
2. When two numbers are added with the complement sign, if the highest bit (symbol bit) has an incoming bit, the carry is discarded. (Modulo concept, modulo 10000 0000)
For example: 1111 1111 1000 (-1) + 0001 127 1000 (-0000) = 128 (-, in fact, the highest bit has three 1, after one carry, keep one)
1111 1110 (-2) + 0000 0100 (4) = 0000 0010 (2)
3. Module rules (Self-estimation)
1. The complement mode is 10000 0000
2. the anticode modulo is 1000 0000 (we can also know from the definition of the anticode, that is, the anticode operation does not involve the symbol bit)
3. Module Interpretation
In daily life, there are many examples of subtraction and addition. For example, the clock runs at 12 bits, and can also be regarded as zero.
There are two ways to adjust the hour hand from 10 to 5:
1. Dial 5 cells in the clockwise direction, which is equivalent to subtraction: 10-5 = 5
2. Dial 7 cells clockwise, equivalent to addition: 10 + (12-5) = 12 + 5 = 5 (12)
2. Definition of source code, reverse code, and complement code (Mainly about negative numbers)
1. The original codes, backcodes, and supplementary codes of positive integers are the same.
2. Negative Number:
1. The original code is the original representation method.
2. The reverse code is the reverse code of the original code except the symbol bit (highest bit ).
3. complement = reverse code + 1
3. Example: in a single byte: (8 bits)
-1 original code 1000 0001 (obtain the true value through the original code)
Reverse Code 1111 1110
Complement Code 1111 1111 (get binary code through complement code)
-2 original code 1000 0010
Reverse Code 1111 1101
Makeup 1111 1110
** And so on : Original code 1000 0000 (-128) (important)
Reverse Code 1111 1111
Fill in 1000 0000 1111 (1111 1000 + 1 = 0000 1111 1111, which is actually the seven digits after,
The 1st bits indicate that the symbol bit remains unchanged. Therefore, when the 8th bits are entered, the system will overflow and be discarded,
That is to say, the anti-code modulo is 1000 0000, and the re-code modulo is: 10000 0000 is one more than the anti-code)
If you use the complement code to reverse push the source code
Makeup 1000 0000
Anti-Code 1111 1111 (1000 0000-1 = 1000 0000 + 1111 1111 (equivalent to adding two complement codes, rule of available mode) = 1111 1111)
Original code 1000 0000
4. Emotion: many groups of people cannot explain it, so they arbitrarily say that the binary value of-128 is 1000 0000, and that it does not have an anti-code or the original code, or "provision"
I have not found such an official rule (I personally think this is not rigorous and irresponsible, huh, huh)

5. Specific computing Demonstration:
1 + (-1) = 0
0000 0001 + 1111 1111 = 0000 0000
1 + (-2) =-1
0000 0001 + 1111 1110 = 1111 1111 (-1)
2 + (-1) = 1
0000 0010 + 1111 1111 = 0000 0001
(-128) + 1 =-127
1000 0000 + 0000 0001 = 1000 0001 (Supplement)
1000 0001 (Supplemental code)
1000 0000 (reverse code = complement-1)
1111 1111 (original code =-127)
3. An incorrect explanation seems to have been written into a book (I think)
Another reason is that the number of machines with 0 has two encodings. The original code and the reverse Code represent 0.
There are two forms: + 0 and-0. We know that + 0 and-0 are the same. In this way, the range of the 8-bit original code and the integer represented by the anticode is-127 ~ + 127
(11111111-01111111), and when the supplementary code is used, 00000000 is + 0, that is, 0; 10000000 is no longer-0, but-128. In this way,
The value range of the complement value is-128 ~ + 127, not only adds a number representation range, but also ensures the uniqueness of the 0 encoding.

My point of view: the people who wrote the above mentioned also said that 10000000 (complement code) does not have an anti-Code or an original code. In this case, how can we draw a conclusion?
1000 0000 used to represent-0. In fact, through the above analysis, 1000 0000 has an inverse code (1111 1111) and an original code (1000 0000)

4. some good concepts:
because the symbols in the computer are the same as numbers, they must both be represented by binary numbers. Therefore, positive and negative numbers must also be represented by 0 and 1.
the highest digit 0 indicates positive and 1 indicates negative. This digital intra-device representation is called "number of machines ",
the external positive and negative numbers of corresponding machines are called "true values". The process of displaying a real value table as the number of machines with binary strings is called encoding.
5. reference: http://www.cnblogs.com/ASPNET2008/archive/2009/04/29/1446471.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.