Java unsigned shift (>>>) and signed Shift (>>)

Source: Internet
Author: User

>> (<<) in Java represents a signed shift. <<< (>>>) denotes unsigned shift

Such as:

int num = 22;

Binary is 0001 0110, num>>>1, right shift one becomes 0000 1011 (11)

int num =-22

Binary with complement: 1110 1001, num >>>1 unsigned Right shift one: 0111 0100

>> After moving right, the leftmost symbol is used as a substitute. >>> move right to the left with 0 alternates

1  Public classTest {2      Public Static voidMain (String args[]) {3         intnum =-22;4         inttemp = num >>> 1;5SYSTEM.OUT.PRINTLN ("temp =" +temp);6temp = num >> 1;7System.out.print ("temp =" +temp);8     }9}

Output

temp = 2147483637
temp =-11

Java unsigned shift (>>>) and signed Shift (>>)

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.