+ 5
How it works? Why the answer 8?)
int x=2; Console.Write(x<<2);
2 Answers
+ 2
The left-shift operator (<<) shifts its first operand left by the number of bits specified by its second operand.
In this case:
10 << 2 -> 1000,
which is equal to eight in binary.
Reference:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/left-shift-operator
+ 14
Think binary ;)
<< and >> are bit shift operators.
<< shifts left and >> right.
<< 2 shifts to positions left.
2 is 0010 in binary.
Now you shift the 1 two places to the right.
0010
0100
1000
1000 binary is 8 decimal.