Java - Bitwise left shift operator <<

What is Bitwise left shift operator?

The bitwise left shift operator << shifts all the bits to the left by the number of bits specified as its right-hand operand.

It inserts zeros at the lower-order bits.

Shifting 1 bit to left is same as multiplying the number by 2.

9 << 1 is 18, 9 << 2 is 36.

00000000 00000000 00000000 00001001   9

0000000 00000000 00000000 000010010   18

000000 00000000 00000000 0000100100   36
public class Main {
  public static void main(String[] args) {
    int i = 9;
    System.out.println("i = " + (i << 1));
    System.out.println("i = " + (i << 2));
  }
}

Quiz