Java shift operation

Source: Internet
Author: User

In Java, the numbers are all signed numbers, positive numbers and negative numbers. in Java, there are two types of shift, symbol bit extension and unsigned number shift.

 

1. Normal shift operation (<<>>)

(1) The positive number symbol is extended and shifted. The symbol extension is not a symbol correction. That is to say, the symbol bit will not be corrected when the overflow symbol changes.

Example: 1 <31 =-2147483648

(2) Extend the shift of the negative number symbol, that is, how to move the negative number or the negative number, it is impossible to change to a positive number. It is done by adding 1 to the head for every 1 bit of movement, instead of moving N bits at a time and then completing 1.

Example:-1> 10 =-1

 

2. Add 0 shift operations (>>,<<)

Directly add 0, regardless of positive or negative number.

 

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.