This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dans Question -Operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dans Question -Operators" Watch "Dans Question -Operators" New topic

Dans Question -Operators

shetal bansal
Ranch Hand

Joined: May 09, 2005
Posts: 63

What is the result of attempting to compile and run the program?
Answer is 31,0.
Can anyone explain me the exact pen and paper calculation for the same.As I feel the calculation will be pretty hectic, considering that int is 32 bit.
Henry Wong

Joined: Sep 28, 2004
Posts: 18534

Hope this helps,
[ May 18, 2005: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Note: for shifting, only the lowest five bits are used

And in case of long, use lowest six bits.
shetal bansal
Ranch Hand

Joined: May 09, 2005
Posts: 63
thanxs a lot for the nice explanation!!
Just wanted to confirm one thing, that in case of integers, for shifting lowest 5 bits are used and in case of shifting of long, lowest 6 bits are used?
Are these the only two cases?Meaning no other special cases where the no. of bits vary?
vinuharan haran
Ranch Hand

Joined: Feb 26, 2005
Posts: 64
Those are the only possiblities.All other types byte,short,char are promoted to int.

The type promotion is applied to both the operators separately.
The resulting type and number of bits shifted depends only on the type of the L.H.S operator.
Hope this helps....
[ May 19, 2005: Message edited by: vinuharan haran ]
wood burning stoves
subject: Dans Question -Operators
Similar Threads
MouseListener - mouseEntered question.
Two's complement question
Question on Thread example in Kathy Sierra 1.4 book
An odd question...
quick paging calculation question