1.按位右移運(yùn)算符(>>)
將數(shù)據(jù)除以2^n(2的n次方)
2.按位左移運(yùn)算符(<<)
將數(shù)據(jù)乘以2^n(2的n次方)
使用按位運(yùn)算符計(jì)算數(shù)據(jù)
#include <iostream>
#include <cstdlib>
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;
system("pause");
return 0;
}
效果圖

image