Why output of the following code is 8? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why output of the following code is 8?

int x = 2; Console.Write(x<<2); Thanks.

2nd Jun 2017, 3:16 PM
Niraj Patidar
Niraj Patidar - avatar
1 Answer
+ 6
In binary, x is 10(2). <<, meaning pushing all bits to left, push those bits twice to left. Then it becomes 1000(2). And it's 8 in decimal.
2nd Jun 2017, 3:27 PM
OrbitHv [Inactive]
OrbitHv [Inactive] - avatar