Binary implementations of Java plus and minus

Source: Internet
Author: User

 The basic types of integers in Java are Byte,short,int,long, 1, 2, 4, 8 bytes in size, and a byte size of 8 bits, which is 8 binary codes (0/1).

The binary code in the computer is divided into the original code, the inverse code, the complement. The number in the computer is stored in the original code, and negative numbers are stored in twos.

The original code is in the form represented in the machine, the first 1 represents a negative number, and 0 represents a positive number. For example, in the case of byte type, 0000 0001 represents a positive number 1,1111 1111 represents-1. Positive number of the original code, anti-code, the same complement, negative number of the anti-code for the original code in addition to the symbol bit, the other bit reverse. The complement is the inverse code plus 1. For example, 3 of the original code is 1000 0011, the anti-code is 1111 1100, the number in the computer is 1111 1101. Complement the original code with the same complement to the original code.

NOTE: 1000 0000 on the computer represents-128.

In Java if two-128 is added, regardless of rounding, the result is 1 0000 0000, because the byte type, so 1 is discarded, and the final result is 0.

Similarly integer.max_value+integer.max_value results are-2.

Binary implementations of Java plus and minus

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.