Java left and right shift

Source: Internet
Author: User

Search today to a more useful online compiler, I hope to share with you.

In addition to Java and C + + ..., the address is http://www.tutorialspoint.com/compile_java_online.php

In addition today again reviewed the Java left and right shift, here for negative numbers for example:

Positive and negative numbers are expressed in the form of complement in Java

For example, 2 is represented in the computer as 11111111 11111111 11111111 11111110

1. Move left

The result of the -2<<2-2 left Shift 2 bit is: 11111111 11111111 11111111 11111000 (Low-fill 0)

Above is the complement, the highest bit is 1 indicates that this is negative, the complement of negative number is the original code of positive number: "The highest bit is 1, the rest of you take the opposite, and finally add 1" to get.

So push back and you'll know that -2<<2 's results actually represent the number of 10000000 00000000 00000000 00001000 (-8)

2. Move Right

The high is 1, 1, and the high is 0.0

-2>>2:11111111 11111111 11111111 11111111

10000000 00000000 00000000 00000001 (-1)

3. The shift operator can be combined with "="

A<<=2 represents the value of a 2-bit left shift to a

4. Add: The Java Virtual machine masks The small end of the problem, the interior is small.

Java left and right 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.