-128 contains 8-bit binary representation of the original code, anti-code, and complement code

Source: Internet
Author: User

I. Concept of Modulo (I will only list one example. For details, refer to "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:
<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 (Mode: 12)

Ii. Use of the modulo (using the modulo to obtain the complement code)
1,
The following code is obtained:To convert a negative number to a positive number that can be added. So, complement the negative number = the absolute value of the Modulo-negative number
For example,-1 Completion code: 1111 1111 (1 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, where the highest bit represents the symbol bit, without arithmetic computation)
3,Conclusion: The complement 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)
4,Conversion between the source code and the complement code:
(1)Complement = source code-1, And then reverse (easy to understand)

OrComplement = reverse code + 1(Easy description and reasoning)
(2) Demo: complement = reduce the original code by 1, and then reverse
For example, the original code of-1 is 1000 0001 => 1000 0000 (after 1 is subtracted) => 1111 1111 (after reverse retrieval ).
(3) Demo: complement = anti-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 1 0000 0000 (the highest bits are not sign bits, and the complement code is obtained by subtracting the absolute value of the negative number)
3. deduce-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)
Let's take a look at the concept of the original code: the positive sign bit is 0, the negative sign bit is 1, and the other bits represent the absolute value of the number according to the general method.
Is 0 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)
Let's take a look at the formula for the negative complement: the complement of the negative number = 1 0000 0000 (Modulo)-the absolute value of the number
For example:-1 1111 1111 = 1 0000 0000-0000 0001
-2 1111 1110 = 1 0000 0000-0000 0010
If-0 is a negative number
-0 of the complement code should be 1 0000 0000-0 (this 0, let's call it 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: 1 0000 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 it 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 uniquely indicates-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, the real addition is the seven digits after 1111 1st, and the bits are the symbol bits, so, when the number reaches 8th bits, the overflow will be discarded)
2,To sum up:

<1> the-128 complement code is 1000 0000,
<2> the source code, reverse code, and complement code of 0 are the same (that is, 0000 0000)
<3> If-0 is regarded as a negative number, 1000 will be ambiguous (in fact, only one 0000 complement code of 0 is used)

 

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.