<< operator in C++?
我是C ++新手,下面的<<
声明中的确切含义是什么,谢谢。
if (Val & (0x0001 << 0))
{}
else
{}
It is a shift-left operation. If you have:
a << b
where a
and b
are integral types (char, short, long, etc.), then the bits in a
are shifted left b
places with zeroes filling in on the right. In other words, a
is multiplied by 2^b
.
Example:
12 << 3
12 (decimal) = 00001100 (binary)
shift left 3 places:
00001100 becomes 01100000
which is 96 (which is 12 * 8
or 12 * 2^3
)
It means shift 0x0001 number 0 bits to the left. In that specific case, it does nothing.
For example, if it was (0x0001 << 4)
, 0x0001 would become 0x0010. Each position shifted left is like multiplying the number by 2.
That is a bit shift operator.
But when integers aren't involved, beware of an underlying overloaded operator.
链接地址: http://www.djcxy.com/p/72492.html上一篇: 使用按位运算符
下一篇: <<在C ++中的运算符?