+ 2

Templates and << Operator

So https://code.sololearn.com/c3LH9lXZJV24/?ref=app I got a number and don't understand the process behind it Can someone explain it in bits? I tought the << operator moves bits from right to left and tried to understand how 1100 ( 12 ) << 1100 ( 12 ) works If its not about bits then I apologies and ask for an explanation Also can I define a template function above main and declare it after main? If yes how? I'm aware about google research but still tought I ask here since I only play challenges in SL

26th Apr 2017, 1:16 PM
Vodolle
Vodolle - avatar
2 Answers
+ 27
12<<12 shifts the number 12 to left 12 times, and thus it produces a large number. Let's try to trace the following : Left shift: 12<<2 = 1100 << 2 1st shift: 11000 (24) 2nd shift: 110000 (48) So 1 left shift actually multiplies the number with 2. Edit: 12<<12 will multiply 12 with 2 twelve times Right shift: 12>>2 = 1100>>2 1st shift: 0110 (6) 2nd shift: 0011 (3) So 1 right shift divides the number by 2 I'm not sure about the second question, I hope someone else will answer that :)
26th Apr 2017, 1:41 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 4
@Shamima Oh thanks so it was about Bitshifting afterall Thanks its clear now ^ - ^)/
26th Apr 2017, 1:49 PM
Vodolle
Vodolle - avatar