This week's book giveaway is in the JDBC forum. We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line! See this thread for details.

Im trying to execute the below program, im not able to understand the leftshifting functionality

public class shiftdemo { public static void main(String[] args) { System.out.println("14 in binary format is:"); System.out.println("1110 \n"); System.out.println("Now right shifting the bits by 2"); System.out.println("14>>2="+(14>>2)); System.out.println("now left shifting the bits by 2"); System.out.println("14<<2="+(14<<2)); } } Output

C:\PROGRA~1\Java\JDK15~1.0_0\bin>java shiftdemo 14 in binary format is: 0000 00000 0000 1110

Now right shifting the bits by 2 14>>2=3 now left shifting the bits by 2 14<<2=56

Im not clear how this left shifting works. Please help me understand this. Thanks

If you start with 0000 00000 0000 1110 and shift all the bits right by two places you get 0000 00000 0000 0011 (the rightmost two bits are lost) which is 3

If you start with 0000 00000 0000 1110 and shift all the bits left by two places you get 0000 00000 0011 1000 (the two empty bits on the right are filled with zero) which is 56 [ November 21, 2008: Message edited by: Joanne Neal ]