先上代码吧,看了之后你就会懂
#pragma GCC optimize(1) #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define rep(i,j,k) for(register int i=(j);i<=(k);++i) using namespace std; template<class T> inline void read(T &x) { x=0; register char c=getchar(); register bool f=0; while(!isdigit(c))f^=c=='-',c=getchar(); while(isdigit(c))x=x*10+c-'0',c=getchar(); if(f)x=-x; } int main() { int num = 32; int half = num >> 1; int quarter = num >> 2; int doublenum = num << 1; int quadruple = num << 2; printf("half = %d quarter = %d doublenum = %d quadruple = %d ", half, quarter, doublenum, quadruple); return 0; }
half = 16
quarter = 8
doublenum = 64
quadruple = 128
注意:
不能出现cout<< 2>>1 <<endl; 必须得打上括号 cout<< (2>>1) <<endl; 因为>>和<<运算级是一样的,并且这里是输入输出运算符,编译器会无法识别。