File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Similar Threads
shift question
Please clarify this bitwise shifting
Shift operator....
Shift operator doubt