True Value, original code, anticode, complement and shift Interpretation

Source: Internet
Author: User
Simple definition
    • True Value:

The true value of a positive or negative number is a positive or negative sign before the binary number corresponding to the absolute value.

For example, the true value of 2 is + 00000010.
-2 has a true value of-00000010.
(The positive number can be omitted)

    • Original Code: (the first digit of the original code indicates the symbol bit, 0 indicates positive, and 1 indicates negative)

The original code of positive numbers is the corresponding binary number, for example, the original code of 2 is 00000010

The original code of a negative number is the first digit of the binary number corresponding to its absolute value to 1, for example, the original code of-2 is 10000010

    • Anti-code:

The reverse code of a positive number is the same as the original code.

A negative number is used to reverse the original code, except for the symbol bit.

    • Complement:

The positive complement is the same as the original code.

The complement of a negative number is to add 1 at the end of the anti-code.

    • Code transfer:

The QR code is obtained after the signed bits of the complement code are reversed.

Take the 8-bit binary number as an example:
2-2
True Value: 00000010-00000010
Original code 00000010 10000010
Reverse code 00000010 11111101
Makeup 00000010 11111110
Code transfer 10000010 01111110

Why do I need to use the original code, reverse code, and complement code?
    • Original code:

In daily life, we use decimal to represent a number. If it is a negative number, we add a symbol ("-") before the number.

However, in a computer, only 0 and 1 can be identified. (Pulse-like changes .....).

In this way, you need to use binary to represent the number.

For the identification of negative numbers, the highest binary number is the storage symbol (0 is positive, 1 is negative), so that the original code of the number of machines is generated.

    • Anti-code:

When using the original code for calculation, for example:

Decimal (1) 10-(1) 10 = (1) 10 + (-1) 10 = (0) 10

Binary (0 0000001) ORIGINAL + (1 0000001) original = (1 0000010) original = (-2)

Obviously, this result is incorrect. In this way, we can conclude that there is a problem in using the original code for addition and subtraction when negative numbers are involved.

As a result, try to use the back code for calculation:

(0 0000001) + (1 1111110) = (1 1111111) = (1 0000000) = (-0)

It looks close, but there is still a problem. The result should be (+ 0)

In terms of (+ 0) and (-0), there is no positive or negative difference in people's computing concepts. So we introduced the concept of Code complement.

    • Complement

The complement of a negative number is to add one to the anticode, while the complement of a positive number remains the same, and the source code of a positive number is the same. (-128) is used in the Supplementary Code instead of (-0). This is prescribed by humans, so the expression range of the Supplementary Code is:

(-128 ~ 0 ~ 127) a total of 256.

(0 0000001) Fill + (1 1111111) Fill = (0 0000000) Fill = (0)

This is correct.

Therefore, the purpose of code complementing is:

(1) Enable the symbol bit to join the operation with the valid value to simplify the operation rules. The sign bit in the number of complement machines is not imposed. It is a natural component of the data and can be involved in operations normally.

(2) convert the subtraction operation to addition, further simplifying the line design of the calculator in the computer.

All these conversions are performed at the bottom layer of the computer, and all the original codes are used in the assembly, C, and other advanced languages we use.

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.