Hi Ashish,

I have writeen a small program to ease the shifting thing. Change according to your req.

public class ShiftTest {

public static void main(

String[] args) {

int toBeShifted = 32;

int shiftBy = 34;

System.out.println("Binary representation for " + toBeShifted + " >> " + shiftBy + ":");

System.out.println("Binary for " + Math.abs(toBeShifted) + ": " + append(Math.abs(toBeShifted)));

System.out.println("Complement of above: " + append(~Math.abs(toBeShifted)));

System.out.println("Add 1: " + append((~Math.abs(toBeShifted)) + 1));

System.out.println("Shift by " + shiftBy + "(" + shiftBy%32 +"): " + append(((~Math.abs(toBeShifted)) + 1)>> shiftBy));

System.out.println("Complement: " + append(~(((~Math.abs(toBeShifted)) + 1)>> shiftBy)));

System.out.println("Add 1: " + append((~(((~Math.abs(toBeShifted)) + 1)>> shiftBy)) + 1));

System.out.println("=: " + (toBeShifted >> shiftBy)) ;

}

static String append(int no) {

String str = "";

int length = (Integer.toBinaryString(no)).length();

for( int i = 0; i < 32 - length ; i++) {

str += "0";

}

str += Integer.toBinaryString(no);

return str;

}

}

Santhosh.