Java shift Operator Experiment Program:<< (left), >> (with symbol right shift) and >>> (unsigned Right shift)

Source: Internet
Author: User





public class TXs {



static void Leftbit () {
int i; Integer length 32 bits per/bit
int Num=0xffffffe; 1111 1111 1111 1111 1111 1111 1110//28
for (i=0;i<28;i++) {
The loop moves one bit to the left, discards the highest bit, and 0 is the lowest bit.
num=num<<1; 1111 1111 1111 1111 1111 1111 1110 0//29
1111 1111 1111 1111 1111 1111 1110 00//30
1111 1111 1111 1111 1111 1111 1110 000//31
1111 1111 1111 1111 1111 1111 1110 0000//-32
1111 1111 1111 1111 1111 1111 1100 0000//-64

SYSTEM.OUT.PRINTLN (num);
}
}

static void Rightbit () {
int i; Integer length 32 bits per/bit
int Num=0xffffffe; 1111 1111 1111 1111 1111 1111 1110//28
for (i=0;i<4;i++) {
The loop moves right one sign bit to the left, and the symbol bit
Num=num >> 1; 1111 1111 1111 1111 1111 1111 111//27
1111 1111 1111 1111 1111 1111 11//26
1111 1111 1111 1111 1111 1111 1//25
1111 1111 1111 1111 1111 1111//24

SYSTEM.OUT.PRINTLN (num);
}
}

Unsigned Right Shift
//
static void Unregist_rightbit () {
int i; Integer length 32 bits per/bit
int Num=0xffffffe; 1111 1111 1111 1111 1111 1111 1110//28
for (i=0;i<4;i++) {
The loop moves one at a time to the right one ignores the sign bit extension. 0 complement Maximum bit
Num=num >>> 28; 1111 1111 1111 1111 1111 1111 111//27
1111 1111 1111 1111 1111 1111 11//26
1111 1111 1111 1111 1111 1111 1//25
1111 1111 1111 1111 1111 1111//24

SYSTEM.OUT.PRINTLN (num);
}
}
public static void Main (string[] args) {
TODO auto-generated Method Stub
Leftbit ();
Rightbit ();
System.out.println ("================");
Unregist_rightbit ();
}


}

Java shift Operator Experiment Program:&lt;&lt; (left), &gt;&gt; (with symbol right shift) and &gt;&gt;&gt; (unsigned Right shift)

Related Article

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.