+ 3

How to answer this code 8?

Hello friends I do not know, why the output of this code is number 8? Please look at the code below: 👇 https://code.sololearn.com/cGR7eLHGcyiR/?ref=app

30th May 2018, 7:19 AM
Saleh đŸ‘šđŸ»â€đŸ’»
Saleh đŸ‘šđŸ»â€đŸ’» - avatar
1 Answer
+ 2
The left-shift operator (<<) shifts its first operand left by the number of bits specified by its second operand. For eg here x = 2 which is equivalent to 0010 in binary when consider for four lower bits. Since << has 2 in its right operand that means it will shift left operand value '0010' by shifting two bits to the left ie 0010 -> 0100 : in first left shift 0100 -> 1000 : in second left shift The decimal (numeric) representatioin of 1000 is 8. So the output of the above code is 8
30th May 2018, 7:47 AM
Gopal Gautam
Gopal Gautam - avatar