:<<,>>,>>> summary of shift operators in Java

Source: Internet
Author: User

There are three kinds of shift operators in Java

<<: Left shift operator, num << 1, equals num multiplied by 2

>>: Right shift operator, NUM >> 1, equivalent num divided by 2

>>>: Unsigned Right shift, ignore sign bit, empty 0

Let's see how these shift operations are used.

1 /** 2 * 3*/ 4Package com.b510.test;5  6 /** 7 * @author Jone hongten 8 * @create date:2013-11-2 9 * @version 1.010*/ One  Public classTest { A  -      Public Static voidMain (string[] args) { -         intNumber =Ten; the         //Binary binary of primitive number -printinfo (number); -Number = number <<1; -         //Move left one +printinfo (number); -Number = number >>1; +         //Move Right One Aprintinfo (number); at     } -      -     /**26 * Outputs a binary number of int * @param num28*/ in     Private Static voidPrintinfo (intnum) { -System. out. println (integer.tobinarystring (num)); to     } +}

The result of the operation is:

1010101001010

Let's align the results above:

43210      Number of digits
--------1010 Decimal: original number number10100 decimal: shift left one digit = number << 1; 1010 Decimal: Ten right shift one number = number >> 1;

Look at the above demo, now is not the left shift and right shift to understand a lot of it

For:>>>

Unsigned right shift, ignore sign bit, empty 0

Value >>> num--num Specifies the number of bits to shift the value to move.

Unsigned right-shift rules only remember one point: ignoring the sign bit extension, the 0-bit unsigned right-shift operator >>> is only meaningful for 32-bit and 64-bit values

:<<,>>,>>> summary of shift operators in Java

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.