Vijay,
I wrote the following code. Play around with it. It cleared my doubts.
// Vaneet Bhutani
// Prog Number: 1.
// Module: Shift Operators 101
// Expected output: 1 unsigned right shift:2147483519
// i:-257
// 2 signed right shift:-65
// i:-257
// 3 signed left shift:-2056
// i:-257
import java.lang.*;
public class ShiftTest
{
public static void main(
String args[])
{
int i =-257; //try i=257
int j;
j=i>>>1;
//Remember the brackets. Otherwise, you will recv. Invalid arguments to >> error message.
System.out.println("1 unsigned right shift:" + j);
System.out.println("i:"+i);
System.out.println("2 signed right shift:" + (i>>2));
System.out.println("i:" + i);
System.out.println("3 signed left shift:" + (i<<3));
System.out.println("i:"+i);
}
}
Originally posted by Vijay Naidu:
Hi every one. This is my first post here. I am preparing for the SCJP, and am facing difficulty in solving the shift operators problems. I request that any good links on this subject be posted, which explains how to solve them.
Thanks.
Vijay Naidu