C - What is this syntax about? <<
what does this sybol means please? "<<" fo开发者_如何学Cr example: if (1 << var)
I want the name of the thing to study. Thank you.
It shifts the bits in the integer 1 var
positions to the left. So in effect it calculates 2 to the power of var
.
See the article on bit shifts on wikipedia.
That is a "left bit shift" operator. In your example, it shifts 0000..00001 left "var" places. So if var is 1, this is the same as "1 << 1" which shifts 0001 to 0010, which is 2. If var was 2 the answer would be 0100 (4), etc. If this isn't making sense, you'll need to read up on binary arithmetic.
That's the left bitwise shift operator
.
The other bitwise shift operator
is >>
.
The name is The C Programming Language.
It is the left shift operator.
You might want to read about bitwise operations, and more specifically, bitshift operators.
<<
is a bit manipulation operator. Specifically <<
performs left shift operation. This achieves the effect of multiplying the underlying value by power of 2.
More information could be found at: http://en.wikipedia.org/wiki/Bit_manipulation
精彩评论