Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Unsigned right-shift operator

Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!