Java Left Shift Operator

Chapter: Operators Last Updated: 04-09-2018 18:23:28 UTC

Program:

            /* ............... START ............... */
                
public class JavaLeftShift {

	/* left shif Operators */

	public static void main(String args[]) {

		System.out.println(1 << 2);// 1*2^2=1*4=4
		System.out.println(1 << 3);// 1*2^3=1*8=8
		System.out.println(1 << 4);// 1*2^4=1*16=16
		System.out.println(11 << 2);// 11*2^2=11*4=44
		System.out.println(14 << 3);// 14*2^3=14*8=112

	}

}
                /* ............... END ............... */
        

Output

4
8
16
44
112

Notes:

  • Left shift operator "<<" shifts a bit pattern to the left.
  • For Eg : 10 << 2 - Here bit of 10 moves to left two place and fill the right place with zero.
  • If the left side operand is one ( 1 << 2) we can use like 2^n.
  • Due to left shift of values , we will get the result as high value than input. But for right shift we will get the smaller value than input.

Tags

Java Left Shift Operator, shift Operator

Similar Programs Chapter Last Updated