Negative binary representation

Source: Internet
Author: User

Negative binary representation

 

First understand several concepts

 

[1] source code:

· Original codes of positive numbers are converted to binary values by absolute values.

· The original code of a negative number is converted to a binary value based on the absolute value. The highest bit is supplemented with 1 (the highest bit of a signed integer is used to indicate positive/negative, 0 is positive, and 1 is negative)

 

Example:

Source code of integer 5

00000000 00000000 00000000 00000101

 

Source code of integer-5

10000000 00000000 00000000 00000101

 

[2] Anti-code:

· Positive anticode, which is the same as the original code

· Negative Inverse code. The symbol bit remains unchanged, and the rest are reversed.

 

Example:

Source code and reverse code representation of integer 5

Original code: 00000000 00000000 00000000 00000101

Reverse code: 00000000 00000000 00000000 00000101

 

Source code and reverse code representation of integer-5

Original code: 10000000 00000000 00000000 00000101

Reverse code: 11111111 11111111 11111111 11111010

 

[3] Complement

· Positive complement, which is the same as the original code

· Complement a negative number. The symbol bit remains unchanged, and the rest are reversed. The second bit + 1

 

Example:

Back-code and complement representation of the source code of integer 5

Original code: 00000000 00000000 00000000 00000101

Reverse code: 00000000 00000000 00000000 00000101

Makeup: 00000000 00000000 00000000 00000101

 

Source code, reverse code, and complement expression of integer-5

Original code: 10000000 00000000 00000000 00000101

Reverse code: 11111111 11111111 11111111 11111010

Makeup: 11111111 11111111 11111111 11111011

 

[4] Special

For the sake of simplicity, the char with a length of 1 byte is used as an example.

-128 indicates

1000 0000, so what is the original code of it? The method for obtaining the source code from the source code is the same as that for the source code. First, retain the symbol bit. Other reverse expressions: 1111 1111, plus 1, 0000, and more than 8 digits. Yes, it cannot be expressed here with an 8-digit original code.

 

Then, back to the original code, its original code is also 1000 0000 (the excess is automatically lost). What does 1000 0000 indicate in the original code? -0, but the complement Code specifies that 0 has no positive or negative points.

Let's take a look at how computation is performed in the computer:

For negative numbers, first take the absolute value, then reverse, and add one

-128-> 128-> 1000 0000-> 0111 1111-> 1000 0000

Now let's make it clear.

Therefore, the complement expression of the 8-bit signed integer value range

1000 0000 to 0000 0000, and then to 0111 1111

That is,-128 to 0, and then to 127

End-128 ~ + 127

 

 

 

From: http://blog.sina.com.cn/s/blog_56d8ea900100y65b.html

Negative binary representation

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.