C Language Original code--anti-code--complement

Source: Internet
Author: User

//original code, anti-code, complement#include<stdio.h>#include<stdlib.h>//representation of numeric values--original code, inverse code, and complement//The original code: the highest bit is the sign bit, the rest of you are the absolute value of the number itself//Anti-code://positive: The inverse code is the same as the original code//Negative number: The sign bit is 1, the remaining bits are reversed for the original code//Complement://Positive Number: Original code, inverse code, the same complement//Negative number: The highest bit is 1, the remaining bits are reversed for the original code, plus 1 for the whole .//////in a computer system, the values are all represented by a complement (storage). //The main reason: the use of complement, the symbol and other bits can be processed uniformly, and subtraction can also be processed by addition. //In addition, if the highest bit (sign bit) has a carry, the carry is discarded when the number of two complements is added. //The original code notation is easy to understand, but its biggest disadvantage is the complexity of the addition operation. //this is because, when the two numbers are added, the numbers are added if they are the same number, and if they are different, they are subtracted. //In addition, the size of the absolute value is compared, then the large number minus the decimal, and finally the symbol is selected for the result. //in order to solve these contradictions, people found the complement notation. The complement of the number of machines can be obtained from the original code. //if the number of machines is positive, the complement of the machine number is the same as the original code;//if the number of machines is negative, then the number of the machine is the complement of its original code (except for the sign bit), and in the non-position plus 1 to get. voidMain () {intx =-1; //int is four bytes, 1 bytes 8 bits, so 1 has 32 bits, the highest bit sign bit//original code: 0000 0000 0000 0000 0000 0000 0001//Anti-code: 1111 1111 1111 1111 1111 1111 1111 1110//complement: 1111 1111 1111 1111 1111 1111 1111 1111    inty =3;//positive source code, inverse code, complement all the same//int is four bytes, 1 bytes 8 bits, so 1 has 32 bits, the highest bit sign bit//original code: 0000 0000 0000 0000 0000 0000 0000 0011//Anti-code: 0000 0000 0000 0000 0000 0000 0000 0011//complement: 0000 0000 0000 0000 0000 0000 0000 0011//Beg X+y? //in a computer system, values are stored in the complement of//X's complement: 1111 1111 1111 1111 1111 1111 1111 1111//complement of y: 0000 0000 0000 0000 0000 0000 0000 0011//x+y:0000 0000 0000 0000 0000 0000 0000 0010----- If the highest bit (sign bit) has rounding, the carry is discarded. //so x+y=2printf ("%d\n", x); //Summary : Get the source code from the complement, minus 1 of the complement, and then remove all the sign bit counter System ("Pause");}

C Language Original code--anti-code--complement

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.