【发布时间】:2021-02-11 11:46:57
【问题描述】:
我对左移运算符和 1 感到困惑
int a =1;
cout<<"size of int: "<<sizeof(int)<<endl;
cout <<(a<<31)<<endl;
cout <<(a<<32)<<endl;
结果:
size of int: 4 -2147483648 1
如果我向左移动 32 或 33,它会打印 1。 如何以及为什么它是 1,如果我想左移 1 为零,我该怎么做? 谢谢。
【问题讨论】:
标签: c++ c binary bit-manipulation bit-shift