File APIs for Java Developers Manipulate DOC, XLS, PPT, PDF and many others from your application. http://aspose.com/file-tools
Big Moose Saloon
 Search | Java FAQ | Recent Topics Register / Login Today (12/10) is CodeRanch Day in Manning's Countdown to 2014. Use discount code crdotd14 all month for 50% off every deal. CodeRanch Day is 50% off our pick of books: Secrets of the JavaScript Ninja; The Well-Grounded Java Developer; Java 8 Lambdas in Action; HTML5 in Action; The Responsive Web; and Java Persistence with Hibernate

# shift...Can any one explain me>?

sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
I still cannot understand how are we supposed to calculate such nos.
I went through a mock and found a question :
128 >> 1 gives 64
128 >>> 1 gives 64
128 << 1 gives 256

Ans : All are true.Can any one explain me how is the above expressions true?..with EXPLAINATIONS!!
Sonir
Jim Hall
Ranch Hand

Joined: Nov 29, 2001
Posts: 162
This has been discussed many times. Do a search in this forum for "shift".
sagar patil
Greenhorn

Joined: Jan 04, 2002
Posts: 2

Let me C if I cud B of help.....
these R really crude methods....
RightShift
x >> n
simply means divide x by (2^n)
thus
eg no 1.
128 >> 3
means 128 / (2^3)
=128 / 8
=16
eg no. 2
127 >> 3
=127 /8
Catch here is of -ve numbers :::
-127 >> 3
= -(15+1)
= -16
Similarly,
LeftShift means multiply by 2^n
thus 12 << 3<br /> =12*8<br /> =96<br /> Now comes the unsigned right shift >>>
For positive numbers its the same as >>
so 128 >>> 3
=128/8
=16
for -ve numbers the fundas R required....
no crude methods can help U with these ...

When the going gets tough,<br />the TOUGH get going.....
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
you might want to check out
http://www.javaranch.com/campfire/StoryBits.jsp
its fun and easy!

I agree. Here's the link: http://aspose.com/file-tools

subject: shift...Can any one explain me>?