• 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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!