Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Whizlabs question

 
Latha Kota
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all, I found this question from Whizlabs software, can anybody explain me the answer. I dont have a clear concept of shift operators.
System.out.println(-1>>>1);
The answer is 2147483647
Thanks in advance
Latha
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-1 is the following number in binary:
1111 1111 1111 1111 1111 1111 1111 1111
Shift to the right by one bit to get:
0111 1111 1111 1111 1111 1111 1111 1111 -> a 1 falls off the end here.

The zero on the left appears because we are using the >>> operator (compare with what the >> operator does)
What's the decimal equivalent of the result?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic