On the problems of left-shift and right-shift operation in bit operation

Source: Internet
Author: User

According to my previous learning knowledge, the rules of << and >> operations are as follows:

<&lt: Left-shift operation: is the current binary number to the left to move how many bits, the low empty out of the complement 0. Discard >&gt of high-level emigration;: Right shift operation: is the current binary number of the right to move how many bits, high-empty, the original highest is what, what to fill, low displacement in addition to the discard. Look at the following questions:
 Public classDemo { Public Static voidMain (string[] args) {intA =123; intb = a >> +; intc = a >> -; System. out. println (a); System. out. println (b); System. out. println (c); }}

Output Result:

123123123

  

It seems that this conclusion is not so correct, according to the experiment, according to the data type, int---32 bit a period; long--64-bit one cycle. So loop, not just a simple complement.

On the problems of left-shift and right-shift operation in bit operation

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.