Hanshunping Java note 20th BITS operation shift operation

Source: Internet
Author: User
Tags bitwise

1. In the case of a signed

The highest bit of the binary is the sign bit, and 1 indicates that the integer 1 represents a negative number

Positive source code Anti-code is the same

Negative number of the anti-code = its source symbol bit unchanged, the other bit to reverse

The complement of a negative number = its anti-code +1

0 's anti-code complement is 0.

Java has no unsigned number, and the number in Java is signed

In a computer operation, it's all in the form of a complement.

2. Bit arithmetic

Bitwise AND &: Two bits are all 1 and the result is 1

Bitwise OR |: Two bits have one of 1 and result is 1

Bitwise XOR: Two-bit one is 0, one is 1, and the result is 1

Bitwise de-0->1:1->0

3. Shift Operations

>> Arithmetic right shift: low overflow, sign bit invariant, and sign bit fill overflow high

<< arithmetic left shift: sign bit unchanged, low fill 0

>>> Logic right SHIFT, low overflow, high fill 0

-2 Original code: 10--010

Anti-code: 11--101

Complement: 11--110

Hanshunping Java note 20th BITS operation shift operation

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.