1.按位右移运算符(>>)

将数据除以2^n(2的n次方)

2.按位左移运算符(<<)

将数据乘以2^n(2的n次方)

使用按位运算符计算数据

#include<iostream>

using namespace std;

int main()
{
cout << "Enter a number:";
int Input = 0;
cin >> Input; int Half = Input >> 1;
int Quarter = Input >> 2;
int Double = Input << 1;
int Quadruple = Input << 2; cout << "Half:" << Half << endl;
cout << "Quarter:" << Quarter << endl;
cout << "Double:" << Double << endl;
cout << "Quadruple:" << Quadruple << endl; return 0; }

效果图

C++使用按位右移/按位左移运算符-LMLPHP

05-18 14:07