<< C++ 中的运算符?
我是 C++ 新手,下面语句中 <<
的确切含义是什么,谢谢。
if (Val & (0x0001 << 0))
{}
else
{}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我是 C++ 新手,下面语句中 <<
的确切含义是什么,谢谢。
if (Val & (0x0001 << 0))
{}
else
{}
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
这是左移操作。如果:
其中
a
和b
是整型(char、short、long 等),则a
中的位会移位左边的b
位置,右边填充零。换句话说,a
乘以2^b
。示例:
左移 3 位:
即 96(即
12 * 8
或12 * 2^3
)It is a shift-left operation. If you have:
where
a
andb
are integral types (char, short, long, etc.), then the bits ina
are shifted leftb
places with zeroes filling in on the right. In other words,a
is multiplied by2^b
.Example:
shift left 3 places:
which is 96 (which is
12 * 8
or12 * 2^3
)意思是把0x0001号0位左移。在这种特定情况下,它什么也不做。
例如,如果是
(0x0001 << 4)
,则 0x0001 将变为 0x0010。每左移一个位置就相当于将数字乘以 2。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.