java-bit arithmetic

Source: Internet
Author: User

Original link: Java bitwise operations (SHIFT, bit and, or, XOR, non)

1. Shift Left (<<)

Binary number move left two-bit, low-fill 0

2. Move right (>>)

Binary number move right two bits, high 0

When the decimal number is negative, the binary high point is 1, and the right shift is the high 1

3, unsigned Right shift (>>>)

When the decimal number is negative, the binary high point is 1, and the unsigned right shifts to the high 0

4, Bit and (&)

00, 01, 10 are 0

11 is 1

5 & 3 is 1

0101----5

0011----3

0001----1

5, bit or (|)

00 is 0

01, 10, 11 are 1

5 | 3 is 7

0101----5

0011----3

0111----7

6, Bit XOR or (^)

00, 11 is 0

01, 10 is 1

5 ^ 3 for 6

0101----5

0011----3

0110----6

7, bit non (~)

is equivalent to taking counter

0 is 1

1 is 0

-6

0000 ... 0101----5

1111 ... 1010-----6

java-bit arithmetic

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.