Java bitwise operations (,

Source: Internet
Author: User

Several bit operations:

<: Shifts left (in the direction of the arrow). The removed high position is discarded, and the low position is zero.

>>: Shift right (the direction of the arrow), discard the removal of the low position, and add the high position to the symbol bit (if it is a positive number, add 0, if it is a negative number, Add 1 ).

>>>: The operation shifts right like the previous one, but the high position is zero no matter what the symbol bit is.

&: Perform and operate the two numbers by bit.

|: Perform or operate two values by bit.

^: Perform an exclusive or operation on two numbers by bit.

~ : Returns an inverse operation for each operand.

 

 

Bitwise operations are performed on the original code of the number. The original code of the integer is itself, and the original code of the negative number is the original code of the corresponding integer, and then + 1.

For example:

15 original code: 00000000 00000000 00000000 00001111

-15:

The original code of 15 is reversed:

11111111 11111111 11111111 11110000

Then + 1:

11111111 11111111 11111111 11110001.

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.