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
Java Addition Operator Operators 18-05-2017
Java Right Shift Operator Operators 13-12-2016
Prefix Operator In Java Example Operators 19-06-2016
Logical Operators In Java Example Operators 17-06-2016
Operator Precedence In Java Examples Operators 17-06-2016
Ternary Operators In Java Example Operators 15-07-2016
Relational Operators In Java Example Operators 11-06-2016
Modulus Operators In Java Example Operators 15-07-2016
Increment And Decrement In Java Example Operators 15-07-2016
Boolean Operator In Java Example Operators 15-07-2016
Bitwise Operator In Java Example Operators 16-06-2017
Assignment Operation In Java Example Operators 06-04-2016
Arithmetic Operation In Java Example Operators 11-06-2016

1