a<<b
for integers means left shift. The bit representation of a
shifted to the left b
bits. This is the same as multiplying by (2 by power b
).
So, in your example (1<<1)
there is 1*(2^1)
is 2
, (1<<8)
is 1*(2^8)
is 256
.
It is worth noting that, like other operators in C ++, <<
can be overridden to perform other functions. By default, I / O streams override this statement so that you can write compressed code to send a bunch of parameters to the stream. So you can see this code:
cout << something << somethingelse
and <<
does not mean left shift in this context.
source share