+ 4

Hello everyone please solve my problem. when be I use cout<<(1<<1 ); so answer is 2 and when be use cout<<(2<<2) then answer 8?

https://code.sololearn.com/c3udcSF7VlmK/?ref=app

5th Mar 2019, 2:59 PM
Sandeep
Sandeep - avatar
2 Antworten
+ 16
● Left shift operator works like this: x << y equals to x * 2^y 2 << 2 equals to 2 * 2^2 equals to 2 * 4 equals to 8 ● Right shift operator works like this: x >> y equals to x / 2^y 8 >> 2 equals to 8 / 2^2 equals to 8 / 4 equals to 2 Also you have syntax error on the code at the following line: `cout<<endl<<<(2<<2);` Which should be: `cout<<endl<<(2<<2);` Notice that the `<<<` just before `(2<<2)` causes a problem. Hth, cmiiw
5th Mar 2019, 4:00 PM
Ipang
+ 1
Sandeep 1+1*1=2then 2+2*2=8 it is the method of solving this
20th Apr 2019, 4:05 AM
Aditya sikarwar
Aditya sikarwar - avatar