use*_*260 0 c++ bits bit-manipulation
我正在编码,以下代码没有提供所需的输出.当pos被除以2时,pos&1应该返回余数.当我用pos%2替换pos&1时,一切正常.可能是什么问题呢?
#include <iostream>
using namespace std;
int main(){
int y;
unsigned long long int pos;
cin>>y;
cin>>pos;
int f=0;
while(y>0){
y--;
if(pos&1==0){
f=1-f;
}
pos=pos/2;
}
if(f==1){
cout<<"blue\n";
}
else
cout<<"red\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)