Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)

I am trying to understand the shift operators and couldn't get much. When I tried to execute the below code

System.out.println(Integer.toBinaryString(2 << 11));

System.out.println(Integer.toBinaryString(2 << 22));

System.out.println(Integer.toBinaryString(2 << 33));

System.out.println(Integer.toBinaryString(2 << 44));

System.out.println(Integer.toBinaryString(2 << 55));

I get the below

1000000000000    

100000000000000000000000    

100    

10000000000000    

1000000000000000000000000    

Could somebody please explain?

1 Answer

0 votes
by (46k points)

I believe this might Help:

    System.out.println(Integer.toBinaryString(2 << 0));

    System.out.println(Integer.toBinaryString(2 << 1));

    System.out.println(Integer.toBinaryString(2 << 2));

    System.out.println(Integer.toBinaryString(2 << 3));

    System.out.println(Integer.toBinaryString(2 << 4));

    System.out.println(Integer.toBinaryString(2 << 5));

Result

    10

    100

    1000

    10000

    100000

    1000000

Edited:

Must Read This (how-do-the-bitwise-shift-operators-work)

Browse Categories

...