File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Mock Exam Errata and the fly likes Unsigned right-shift operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Unsigned right-shift operator" Watch "Unsigned right-shift operator" New topic

Unsigned right-shift operator

Lam Thai
Ranch Hand

Joined: Apr 02, 2001
Posts: 117
Question #305 in Javaranch mock exam:
What does an unsigned right-shift operator do to a negative number? You have two choices: a) change its sign and b) keep it negative.
I believe the question needs to be changed as the following snippet of code would cause confusion:
int i1 = -1;
i1 >>>= 1;
System.out.println(x1); // positive - change sign
short s1 = -1;
s1 >>>= 1;
System.out.println(s1); // negative - keeps sign
Maybe the question should be replaced with more specific questions as shown with the examples.
I agree. Here's the link:
subject: Unsigned right-shift operator
jQuery in Action, 3rd edition