+ 4

Why does cout << (1<<1) print 2?

I think it should be 0 as 1 is not less than one so false.

2nd Jun 2017, 7:41 AM
Samanvay Lamba
Samanvay Lamba - avatar
3 odpowiedzi
+ 2
<< is bit operator(left). 1<<1 will shift one bit left. which is equivalent to 2. 1 in binary = 0001 after shifting it left(once) = 0010 0 is added after shifting so 0010= 2
10th Oct 2017, 2:23 AM
Prabhat Singh Rajput
+ 5
<< is a bit shift operator in the context you are using it in. 1 shifted by 1 bit = 2. You need to do 1 < 1 instead
2nd Jun 2017, 7:51 AM
aklex
aklex - avatar
0
Samanvay lamba i am smarter than you
3rd Jun 2017, 7:03 PM
cami cook