Java shift operation

Source: Internet
Author: User
">>>" Logical right shift, add 0 to the left

Note that char, byte, and short are converted to int first when the logic is shifted to the right, and then logically shifted to the right based on the int.

Shift of long type

Long shift is very strange. I don't know what's going on,

Long L =-21474837000l;
System. Out. println (L );
Bitmanipulation. pbinlong ("L", L );
L >>>= 3;
System. Out. println (L );
Bitmanipulation. pbinlong ("L", L );

1111111111111111111111011111100011111111111111111111110111111000

1101111111111111111111111011111111011111111111111111111110111111

If the value of L is a number in the int range, it seems that the content of the first 32 bits is the same. The shift is also based on the 32 shift, and the first 32 bits are respectively shifted to the right three bits.

However, if the value of L is greater than the value in the int range, I don't know how to shift it. In the above example, the logic moves three places to the right, and it seems that the 32-bit values before and after are moved in 110;

In addition, no matter whether the logic shifts right or right, the resulting binary number is the same, but the number after the right shift of the logic is interpreted as the unsigned number.

Why

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.