• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unsigned right-shift operator

 
Lam Thai
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
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.
Regards,
Lam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic