I am wondering to know What is the meaning of operator <<
in
#define x (10 * (1<<12));
I am wondering to know What is the meaning of operator <<
in
#define x (10 * (1<<12));
It's the bitshift operator. <<
is shift left, >>
is shift right. 1 << 12
means shift the value (the int '1') 12 bits to the left.
'1' is 00000000 00000000 00000000 00000001
in binary, if it's a 32 bit integer.
To shift it left 12 places, changes it to: 00000000 00000000 00010000 00000000
If you were to shift 5 << 8
, '5' is 101
in binary, so it'll shift:
00000000 00000000 00000000 00000101
Into:
00000000 00000000 00000101 00000000
See this question for details on the other bitwise operators.
It means 1 shifted 12 bits to the left. You can find thisand more at a quick reference at:
http://www.sourcepole.ch/sources/programming/cpp/cppqref.html