+ 4

[CLOSED] Why is this happening?

Saw this in a challenge question. cout << (1 << 1) Output: 2 I tried it again and... cout << (1 << 2) Output: 4 I was never taught this...

1st Aug 2019, 10:33 PM
UrBoyO
UrBoyO - avatar
3 Answers
+ 5
Left shift by one is equivalent to multiplication by two.
2nd Aug 2019, 8:20 AM
Sonic
Sonic - avatar
+ 2
Martin Taylor Thank you! That makes sense now. I wish they could've put that SOMEWHERE, but that's ok. :)
1st Aug 2019, 10:49 PM
UrBoyO
UrBoyO - avatar