Java Foundation twos complement

Source: Internet
Author: User
Tags bitwise

Binary complement:

1, the internal computer system to store data in binary form.

2. The decimal data entered in the Java program is automatically converted to binary, and the Java internal is also binary for numeric operations, but the result is decimal.

The principle of binary complement:

positive + negative = modulo.

Modulo: The total number of data of a certain type, for example:

4-bit binary number modulo is 2^4=16

8-bit binary number modulo is 2^8=256

Negative number = modulo-positive number, which is the reason for the bitwise negation plus 1.

1, in the computer system, the values are used in twos complement to store.

2. The highest bit of binary is the sign bit, 0 is a positive number, and 1 indicates negative number.

3, positive value is its own, negative value is the highest bit (sign bit) unchanged, the other bit-by-bit inverse, plus 1. (The relationship between positive and negative numbers in a computer is reversed plus one)

4, two number add, if the highest bit (sign bit) has carry, then carry is discarded.

5. The complement operation is closed: The result of the operation is kept within the complement range, and the overrun range is overflow.

Example: (1101) 2

0010 bitwise inversion

0011 plus 1

(1101) 2=-3

The 4-bit twos complement can represent a maximum of 2^4 (16) and a range of -8~7

The 8-bit twos complement can represent a maximum of 2^8 (256) and a range of -128~127

?

Java Foundation twos complement

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.