Best Blogger Tips

Tuesday 18 June 2013

Use of right shift and left shift operator in Java!


Left Shift "<<"

The left shift "<<" shifts the highest order bit to the right for number of times the user specified.

Syntax

value << position 
The value is increased with the double effect according to the value of the position specified.

Example

int value = 10;
int position = 2;

int result = value << position;
So the final value that will be stored in the result variable will be 40.(10,20,40)

Right shift ">>"

The right shift ">>" shifts the lowest order bit to the left for number of times the user specified.

Syntax

value >> position 
The value is decrease with the double effect according to the value of the position specified.

Example

int value = 10;
int position = 2;

int result = value >> position;
So the final value that will be stored in the result variable will be 2.(10,5,2.5(2))

Kindly Bookmark this Post using your favorite Bookmarking service:
Technorati Digg This Stumble Stumble Facebook Twitter
YOUR ADSENSE CODE GOES HERE

0 comments:

Blogger Tricks And TipsComment here

 

| Bloggers Broadcast © 2010. All Rights Reserved | Back To Top |

Your Text Link Here