This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes shift...Can any one explain me>? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "shift...Can any one explain me>?" Watch "shift...Can any one explain me>?" New topic
Author

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
=15 (forget the decimal business...)
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: 1241
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>?
 
Similar Threads
Operator >>>
Conversion 128 to byte
short-circuit operators
Shift operators
Binary/Decimal Conversion