Java shifts left and right, java shifts left and right

Source: Internet
Author: User

Java shifts left and right, java shifts left and right

I found a useful online compiler today and hope to share it with you.

In addition to java, there is also c ++..., the address is http://www.tutorialspoint.com/compile_java_online.php

 

In addition, I have reviewed the left and right shifts of java again today. Here is an example of negative numbers:

Positive and negative numbers are expressed in the form of complement in java.

For example,-2 indicates 11111111 11111111 11111111 in a computer.

 

1. Move left

-2 <2 that is,-2 shifted to the left. The result is: 11111111 11111111 11111111 11111000 (low position 0)

The above is the complement code. If the highest bit is 1, it indicates that this is a negative number. The complement code for a negative number is the original code of a positive number: "The highest bit is 1, the rest are reversed, and then 1 is added.

So let's look at it.-2 <2 actually indicates 10000000, 00000000, 00000000, 00001000 (-8)

 

2. Right Shift

If the high position is 1, then fill 1. If the high position is 0, then fill 0.

-2> 2: 11111111 11111111 11111111

10000000 00000000 00000000 00000001 (-1)

 

3. The shift operator can be used together with "="

A <= 2 indicates that the value after the Left shift of a is assigned to

 

4. Add: the java Virtual Machine shields large-end and small-end problems, and the internal is small-end.

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.