No sign right move, move left, right move operation

Source: Internet
Author: User

Reprint please indicate the source: http://blog.csdn.net/droyon/article/details/9336083

">>>" Unsigned Right shift

Action rule: Regardless of positive negative number, the front is 0.

">>" Move right

Action rule: Positive number front 0, negative number ahead of 1

"<<" Move left

Action rule: Regardless of positive negative, after 0.

public class Bitmovetest {public static void main (String args[]) {//>> right forward complement sign bit//>> equivalent to 2, left-shifted equivalent to multiply by 2 in 
		T i=11;
		int j=-13;
		System.out.println ("Move right, front bit complement symbol bit"); Machine value: 0000 0000 0000 0000 0000 0000 0000 1011//complement value: 0000 0000 0000 0000 0000 0000 0000 1011//Right shift one: 000 0 0000 0000 0000 0000 0000 0000 0101 ("System.out.println value is:" + (11>>1)); The result is: 5//Machine value: 1000 00 00 0000 0000 0000 0000 0000 1101//Complement value: 1111 1111 1111 1111 1111 1111 1111 0011//Right Shift one: 1111 1111 1111 1111 1111 1111 1111 1001 (complement)//Result code: 1000 0000 0000 0000 0000 0000 0000 0111 ( -7) System.out.println (" -13>&
		
		Gt;1 value is: "+ (j>>1));//The result is: -7 System.out.println (" *************************************\n ");
		System.out.println ("Move left, back bit 0"); Machine value: 0000 0000 0000 0000 0000 0000 0000 1011//complement value: 0000 0000 0000 0000 0000 0000 0000 1011//left one: 000 0 0000 0000 0000 0000 0000 0001 0110 System.out.println ("11&The lt;<1 value is: "+ (i<<1)); The result is: 22//Machine value: 1000 0000 0000 0000 0000 0000 0000 1101//Complement value: 1111 1111 1111 1 111 1111 1111 1111 0011//left one: 1111 1111 1111 1111 1111 1111 1110 (complement)//Results Original code: 0110 1000 0000 0000 0000 0000 0001 1010 ( -26) System.out.println (" -13<<1 value is:" + (j<<1)); The result is: -26 System.out.println ("*********
		
\ n ");
		>>> unsigned Right Shift 0 System.out.println ("Unsigned right shift, front complement 0"); Machine value: 0000 0000 0000 0000 0000 0000 0000 1011//complement value: 0000 0000 0000 0000 0000 0000 0000 1011//Right shift one: 000 0 0000 0000 0000 0000 0000 0000 0101 ("System.out.println value is:" + (11>>>1)); The result is: 5//Machine value    : 1000 0000 0000 0000 0000 0000 0000 1101//Complement value: 1111 1111 1111 1111 1111 1111 1111 0011//Right Shift one: 0111 1111 1111 1111 1111 1111 1111 1001 (complement is also the original code) SYSTEM.OUT.PRINTLN (" -13>>>1 value is:" + (j>>>1)); The result is: 21474836 System.out.println ("**********************\ n ");
 }
}

Operation Result:

To the right, the previous bit complement sign bit
11>>1  value is: 5
-13>>1 value is: -7
************************************* to

move left, The value of the next bit complement 0 11<<1 is: The  value of -13<<1 is
: -26 ************************************* The unsigned

right SHIFT, The value of the front complement 0 11>>>1 is:  5
-13>>>1 value is: 2147483641
******************************** *****

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.