• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

operators

 
Rally Krish
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.

public class test {
public static void main(String args[]) {
int x;

x = -3 >> 1;
x = x >>> 2;
x = x << 1;
System.out.println(x);
}
}

ans is given as 2147483646

can anyone please explain

Thanks in advance
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
0000 0000 0000 00113
1111 1111 1111 1100 inverting and adding 1 gives
1111 1111 1111 1101-3

1111 1111 1111 1110>> 1 (sign carried)

0011 1111 1111 1111>>> 2 (0 inserted)

0111 1111 1111 1110hence, the result
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic