Saturday, April 25, 2009

BitWise Right Shift Operator

Bitwise Right Shift Operator which is denoted by >> ,shifts all bits in a value to the right of specified number of times.

Syntax:-

value >> number

where value is,whose bits are to be shifted by number of times specified by number.

for example:- Shifting 32 to right by two positions

24 >> 2 equal to 6
27 >> 2 equal to 6

Explanation:-
24 in binary form is given by 00011000 which after shifting twice returns 00000110 which is equal to 6.Similarly 27 after shifting twice also result in 6 due to loss of lower order bits.

NOTE:-Each time we shift a value we are dividing the value by 2 and leave any remainder.

In this signed right shift operation the sign of value remains preserved.When we are shifting right the higher order bit is shifted and it is replaced by the previous content of highest order bit.This is called as sign extension and it preserves the sign of the value

For Example:-

- 8 >>.1 = - 4 as following happens

11111000 >> 1

11111100 and it is equal to - 4

IMPORTANT:-Value of -1 remains same whether it is shifted or not because its binary value is 11111111.If you will shift this value you will get the same result.

Go to:-

Home
Assignment Operators
Arithmetic Operators
Logical operators
Relational Operators
Conditional Operators
Bitwise Operator Intro
Bitwise Logical operator
Bitwise Left shift Operator

Sponsored Links :-

Get Your SCJP preparation Kit free!!!!!!!
Get Your SCWCD preparation Kit free!!!
Are you Intelligent check here

0 comments:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP