I also want to learn C language-Chapter 5: Coding (1)-"complement"

Source: Internet
Author: User

Original code:

Because the CPU can only be used for addition, people think of this method to achieve subtraction:

 1     -     1     =     1     +  (  -  1  )
In this case, the binary is ( 00000001 ) Original + ( 10000001 ) Original = ( 10000010 ) Original = - 2 /* The highest binary digit 0 of the original code indicates positive, and 1 indicates negative. */

Obviously, the result is incorrect.The reason for this error is that you need to consider both the number symbol and the amplitude when performing addition and subtraction !!! In addition, this will bring about two 0 cases: + 0 = 00000000-0 = 10000000. I think so! CPU can only be added to streamline! It would be a few more cumbersome to do this now! Because it is not so silly. Hey!

Anti-code:

When it is a positive number, its reverse code is the same as the original code! Negative number! The symbol bit is 1, and all other bits are reversed! Likewise, the reverse Code indicates that there is still an appeal.

Complement:

Complete the code! Here is a little story! There is an idiom called "bei zhe! It tells us that a person wants to take a bus to the State of Chu. Because he chooses the opposite direction and does not listen to others' advice, he can only get farther and farther away from the State of Chu. It tells us that no matter what we do, we must first look at the direction to make full use of our favorable conditions. If the direction is wrong, the favorable conditions will only play the opposite role. Actually! The earth is round! Just as if you choose the opposite direction, as long as you persistently move on, you will also reach the place you want to go! Haha! In this case, it takes much time for you to reach your destination. As long as you arrive at the destination, you will not care where you come from, because the result is that you are there. Haha! No matter how many turns you have on the earth, the person at the destination will never know how many turns you have. In a computer, for example, a person can only express 0, 1, regardless of how it is added or added.

In another example, there is now 7 in the decimal number. How can you change it to a number with a single digit of 4? You can do this: 7-3 = 4; you can also do this! : 7 + 7 = 14; Take a closer look, they all have four digits. This is the same as that in the south China region. No matter how many circles you turn around the Earth. In this case, we can conclude that a and B belong to [0, n), and a + B = n. In this case, we can say that these two numbers complement each other !!! That is, a is the complement of B, and B is the complement of! N becomes a model!

Conclusion: So! Now, we can sum up the following: The complement code that requires 1 is to subtract this number by modulo. For example, if the modulo is 10000, we hope to fill 1001, but what about it! Here, 10000 is not the same as the number of 1001 digits, so we can first reduce 10000 by 1, get 1111, and then use 1111 minus 1001 to get 0110. in this way, we know that the difference between the anticode of a number and the complement code is 1, so we get the complement code by adding 1 to the ending number of the anticode!

11 hours have passed since am, but I have finally figured it out! Hey !!! I have heard that pointers are the soul of C language! Now I think it's a soul to complete the code. I 've been thinking about it for a long time!

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.