<<运算符在C ++? [英] << operator in C++?

查看:175
本文介绍了<<运算符在C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C ++的新手,下面的语句<< 的确切含义。

I am new to C++, what's the exact meaning for the << in statement below, Thanks.

if (Val & (0x0001 << 0))
{}
else
{}


推荐答案

这是一个左移操作。如果您有:

It is a shift-left operation. If you have:

a << b

其中 a b 是整数类型(char,short,long等),则 a 中的位左移 b 在右侧填充零的地方。换句话说, a 乘以 2 ^ 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.

示例:

12 << 3

12 (decimal) = 00001100 (binary)

左移3位置:

00001100 becomes 01100000 

这是96(这是 12 * 8 12 * 2 ^ 3

这篇关于&lt;&lt;运算符在C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆