Original code, inverse code and complement

Source: Internet
Author: User

What is a numbering? A rule used to represent numeric values, such as decimal, binary.

Number of machines

The number is represented in binary form, the highest bit is the sign bit, 1 is a negative, and 0 is a positive.

such as: 1---->00000001;-1---->1000 0001

Truth

From the above we know that the number of machines is a form that the computer uses to represent numbers, but for the highest bit is the sign bit. In this case, 1000 0001 represents a true value of 1, not 129. So we call the value of the true actual meaning of a machine number to be a truth.

Original code, inverse code, complement

In general, the code-back code is a way for the computer to store numbers.

Original code

Rule: Symbol bit + absolute value of truth

such as: [+1] the original code = 0000 0001;

[-1] The original code = 1000 0001;

Anti-code

Rule: Positive inverse code for itself

Negative inverse code is the inverse of the original code, but the sign bit is unchanged

such as: [+1] Original code =[+1] Inverse code = 0000 0001;

[-1] Original code = 1000 0001=[-1] Inverse code = 1111 1110;

Complement

Rule: positive complement for itself

The negative complement is based on the inverse code of the original code plus 1.

such as: [+1] Original code =[+1] complement;

[-1] Original code = 1000 0001=[-1] Inverse code = 1111 1110=[-1] complement = 1111 1111;

Why are there three different representations?

Through the above three kinds of we get positive 1 in all cases are consistent: [+1] original \ anti-complement = 0000 00001;

And the inverse code is not consistent.

Inside the computer, in order to make the operation simple. The sign bit is also put into operation so that no computer is required to analyze the role of the sign bit. But we found

[+1] the original code = 0000 0001+[-1] The original code = 1000 0001=0000 00001=1; instead of 0, there was an error. How to solve this problem?

To solve this problem, the inverse code appears

[+1] Original code +[-1] Original code = 1000 0001=[+1] Inverse code = 0000 0001+[-1] Inverse code = 1111 1110=0000 0000 (inverse code) =0000 0000 (original code) =-0;

This solves the problem of the operation between the original code, but the problem appears again -0=1000 0000 (original code), +0=0000 0000 (original code), so that the computer does not look the same. There is no point in it.

[+1] Original code +[-1] Original code = 1000 0001=[+1] complement = 0000 0001+[-1] complement = 1111 1111=0000 0000 (complement) =[0000 0000] (Original code)

This will not be a problem with [0000 0000] (the original code) to represent 0.

In general, in integers, the original code and the complement, the inverse code is the same, for negative inverse code in the case of the symbol bit unchanged, you take the inverse of the results, the complement is the inverse code on the basis of 1. And the original code complement code is to meet the appearance of the computer in the calculation process is simpler and more convenient and appear.

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.