This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes i>>>32  ???  &  i>>>0  and i>>>35 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "i>>>32  ???  &  i>>>0  and i>>>35" Watch "i>>>32  ???  &  i>>>0  and i>>>35" New topic
Author

i>>>32 ??? & i>>>0 and i>>>35

Amit Tyagi
Ranch Hand

Joined: Oct 18, 2000
Posts: 52

Hi,
Could somebody explain me the meaning of unsigned shift.
What exactly is happening here? How integer can be shift by 35 bits?
int i = 5;
i>>>32 or i>>>0 and i>>>35
Thanks
Amit
Sudhir Bangera
Ranch Hand

Joined: Oct 10, 2000
Posts: 50
Hi Amit,
with unsigned shift, it actualy works this way
i>>>35%32 == i >>> 3 (i.e. the remainder of % operation 35 - 32)
so i>>>32 == i >>> 0 (i.e. the value will be same after the operation)
Similarly i>>>64 will also be equivalent to i>>>0.
Hope this helps.....
Amit Tyagi
Ranch Hand

Joined: Oct 18, 2000
Posts: 52
Thanks Sudhir,
How it will work for the negative numbers?
-35>>>35
Amit
ranga akarapu
Greenhorn

Joined: Oct 28, 2000
Posts: 3
to do the above shift operation
step1: you calculate the binary value of 35 i.e 0100011
step2: find the two's compliment of it i.e.it becomes 1011100
step3: then add 1 to it i.e. it becomes 1001101
step4: now shift it by 3 places to its right
note: in first shift itselt it looses its sign
step5: recalculate to decimal form
I hope answer is inline for what u r looking
bye ranga..
Prasad Ballari
Ranch Hand

Joined: Sep 23, 2000
Posts: 149
ranga,
Thanks for your answer.but how should i calculate binary value in the exam.Pls guide me in this regard.
Prasad
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Prasad,
It's easier to work with the formula equivalents for the shift operators.
<pre>
Left-shift: 16<<5 equivalent to 16 * 2<sup>5</sup><br /> Right-shift: 16>>5 equivalent to 16 / 2<sup>5</sup>

</pre>
For the unsigned right shift operator >>>, if the number is positive, the result is the same as the right-shift operator. If the number is negative the equivalent formula is:
<pre>
-16 >>> 5 equiv to (16>>5) + ( 2<<~5)
</pre>
Hope that helps.
------------------
Jane
[This message has been edited by Jane Griscti (edited October 29, 2000).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i>>>32 ??? & i>>>0 and i>>>35
 
Similar Threads
why 270>>33 is not 0?
>>>
shift operators
shift operators
Right shift operators