File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes Roundup #305 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Mock Exam Errata
Reply Bookmark "Roundup #305" Watch "Roundup #305" New topic
Author

Roundup #305

Rob Whelan
Ranch Hand

Joined: Oct 18, 2000
Posts: 33
I could figure out which answer was expected, but this question should probably be reworded or removed:
---------------------
(#305): What does the unsigned right-shift operator do to a negative number?

  • keep it negative
  • change its sign

  • ---------------------
    Well, the behavior most of the time is to change the sign, but try -99 >>> 32 (or -99 >>> 0 -- the same thing, really) -- for the less common result.
    I understand that the question would get kind of awkward if you throw in "unless the number of bits shifted modulo the number of bits in the left-hand operand is 0" ... maybe you can just test the same knowledge by asking "would the result from -309482 >>> 23 be positive or negative?".
Cheryl Gray
Ranch Hand

Joined: Nov 17, 2000
Posts: 44
It seems as though Questions #304 & #305 contradict each other. This is what I understand:
eg. -176 >>2 = Neg #(according to #304) then pos # (according to # 305).
Can someone clarify this please?

Anything is possible to those who believe.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Cheryl, I don't have the exam questions in front of me from the Rules Roundup, but from the way it looks, #304 is the signed right shift operator ( ">>" ) and #305 is the unsigned right shift operator ( ">>>" ). So they are not contradictory. -176 >>2 does give you a negative number as the signed right shift will look at the highest bit and add that in the shift, but unsigned will always add 0's so it will usually be positve.
As Rob pointed out, if the modulo of the number = 0 then nothing happens so it can still be negative. This can also be the case when you use the right shift on bytes, and then cast it back to a byte.
Rob, I beleive someone is working on the Rules Round-up game and adding more questions. I'll check, because you are right, the number can sometimes remain negative.
Bill
Paul Ralph
Ranch Hand

Joined: Aug 10, 2000
Posts: 303
George Brown is finishing up some revisions and I should get the beta from him to test in a few days or weeks.
I'll get a list of all the suggested improvements so I see if they have been implemented.
Paul R
------------------
I wanna be a sheriff when I grow up.


I wanna be a sheriff when I grow up.
Cheryl Gray
Ranch Hand

Joined: Nov 17, 2000
Posts: 44
Thanks Bill. I also have a link which provides extra examples:Right & Left Shift Operators
 
 
subject: Roundup #305
 
Threads others viewed
True / False
Shift operator doubt
binary
Left,Right,Right Zero fill
Unsigned right-shift operator
IntelliJ Java IDE