Unsigned right Shift-1? About Java displacements, most people don't know.

Source: Internet
Author: User
Before looking at the Java source code, see a statement, the integer unsigned right to move a negative (such as 1024>>-22), then exclaimed: "There is this operation, the teacher did not teach Ah", the teacher did not teach.
On the internet, it was found that, for the int type, the shift operation focused only on the back 5 digits (bit) after the shift parameter was converted to binary, while long only focused on the latter 6 digits.

Give me a chestnut:

SYSTEM.OUT.PRINTLN (1024 >>> = 1024 >>>)/True
System.out.println (1024 >>> 10 = 1 024 >>> -22);/True

Where 10 is converted to binary after 1010,42 is converted to binary is 10101,-22 after conversion to binary is 11111111111111111111111111101010, all is the last 5 bit is 01010, so the unsigned right shift after the equality.
Impression should be a lot of books did not explain to this knowledge point, when the university, the teacher did not mention this.

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.