Java operators, bitwise operations

Source: Internet
Author: User

NOTE: Bitwise operators operate on the complement of integers, so the result of the operation is also complementary

& (with Operations)

Convert data to complement form, then treat 0 as False, 1 as true, bitwise AND operation, and finally convert the result to decimal to display

7 0000 0111

& 11 0000 1011

————————————

3 0000 0011

Note:

Even & any number = even
Positive & any number = positive
Odd & 1 = 1
Even & 1 = 0

| (or Arithmetic)

Convert data into complementary form, bitwise OR operation, and finally convert the result to decimal

7 0000 0111

| 11 0000 1011

————————————

15 0000 1111

Note:

Odd | Any number = odd

Negative numbers | Any number = negative

^ (XOR or operation)

Transform the data into a complement, bitwise XOR, and finally convert the result to decimal. Same bit false, different bit true.

7 0000 0111

^ 11 0000 1011

————————————

12 0000 1100

Note:

I ^ i = 0

J ^ 0 = j

I ^ j ^ j = I

~ (take inverse operation)

i = 5

~i =-6

5 Source: 0101

Complement of 5:0101

Inverse operation: 1010

Anti-code: 1001

Source: 1110----->-6

<<, >>, >>>

Https://www.cnblogs.com/chuijingjing/p/9405598.html

Java operators, bitwise operations

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.