This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Shift operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Shift operator" Watch "Doubt in Shift operator" New topic

Doubt in Shift operator

R .sourav nayak
Ranch Hand

Joined: May 14, 2006
Posts: 67
Could some explain me how the out put is i =-1 and j=0 from the following code:

public class Q5
public static void main(String[] args)
int i = 1;
i <<= 31;
i >>= 31;
i >>= 1;

int j = 1;
j >>= 31;
j >>= 31;

System.out.println("i = " +i );
System.out.println("j = " +j);

thanks in advance.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
How do the '>>', '>>>', and '<<' operators work?
I agree. Here's the link:
subject: Doubt in Shift operator