C++中
- 左移运算 a<<b :代表a乘以b个2, 比如:12<<2 等价于 1222
(可理解为二进制数a 向左边移动了b位) - 右移运算 a>>b : 代表a除以b个2,比如: 12<<2 等价于 12/2/2
(可理解为二进制数a 向右边移动了b位)
举例:
#include <iostream>
using namespace std;
int main(){
int a = 101;
printf("%d\n", a <<= 1);
a = 101;
printf("%d\n", a <<= 2);
a = 101;
printf("%d\n", a <<= 3);
a = 101;
printf("%d\n", a <<= 4);
}
// 输出为:
//202
//404
//808
//1616