Confusion in left shift: 1<<i

Hello,
In the section of Bit manipulation left shiift is used extensively. My simple question is that there it is interpreted for two different tasks mentioned below

  1. i = 4
    int mask = i << 4;
    // Binary output: 1000

  2. i=4
    int mask = i << 4;
    // Binary output: 1111

How the same operation can give two different output. Can you please give the difference between both.

Hello @haardpatel07,
Binary output for i<<4 will be 1000000, as for 4 it is 100 and when it shifts 100 4 places left so it will be 1000000. And it will be same everytime.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.