Computer 0 and 1

Source: Internet
Author: User

0 and 1 indicate two states, which are well implemented in reality, such as 1, circuit close, closed 2, high potential, low.

 

Source code, reverse code, and supplementary code.

Negative code: the positive number is the same as the original code. Negative number: The symbol bit is 1. Note: + 0 anti-code: 0000 0000b;-0 anti-code: 1111 11b

Complement: the positive value of the complement code is the same as the original code; the negative value of the complement code: the reverse code + 1 0 of the complement code is only 0000 0000b

 

Why do computers use supplementary codes to store numbers?

Addition and subtraction are easy to implement (carry is easier than bitwise), so the computer does not need to be subtracted.

Example: Computing8-3

1. If the original code is 0000 1000b + 1000 0011b = 1000 1011b, that is,-11

2. If the anti-code is used: 0000 1000b + 1111 1100b = 1 0000 0100b after removing the overflow of one digit: 0000 0100b, that is, 4 is smaller than the actual value 1, so after the reverse code + 1 is the correct result, it is called a complementary code.

 

In addition, the highest bit of a value in Java is a signed bit, and the two values are added together. If the highest bit has a forward bit, discard it. (Beyond the indicated range)

 

Common Questions:

1. Why is-1 expressed in the computer as 1111 1111b?

-1 source code: 1000 0001b

-1 anti-code: 1111 1110b

-1 Completion code: 1111 11b

 

2. Why is-127 of the byte type expressed as 1000 0001b while-128 expressed as 1000 bytes B?

-127 original code: 1111 11b

-127 reverse code: 1000 0000b

-127 completion code: 1000 10000b

 

-128 + 127 =-1

-128 + 0111 1111b = 1111 1111b (full complement)

Launched by Alibaba Cloud. 128 of the complement code (that is, the representation in the computer) is: 1000 bytes B

 

Note: Do not run out of order during computation. Do not use the original code or complement code for computation.

Operations can be performed between the same representation.

 

 

Related Article

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.