请教| ^ &在c++中是什么运算符
请问| ^ &在c++中是什么运算符?
比如
4|6
5&7
8^9
分别等于几??谢谢了
在等 急死了
------解决方案--------------------
用bitset,一目了然。
比如
4|6
5&7
8^9
分别等于几??谢谢了
在等 急死了
------解决方案--------------------
用bitset,一目了然。
- C/C++ code
#include <iostream> #include <string> #include <bitset> using namespace std; void bitCalc(int a, int b, char oper) { bitset<32> b1 = a; bitset<32> b2 = b; bitset<32> b3; switch (oper) { case '|': b3 = a|b; break; case '&': b3 = a&b; break; case '^': b3 = a^b; break; } cout<<"b1="<<b1<<" "<<b1.to_ulong()<<endl; cout<<"b2="<<b2<<" "<<b2.to_ulong()<<endl; cout<<"b3="<<b3<<" "<<b3.to_ulong()<<endl; } int main() { bitCalc(4,6,'|'); cout<<endl; bitCalc(5,7,'&'); cout<<endl; bitCalc(8,9,'^'); cin.get(); return 0; }
------解决方案--------------------
- C/C++ code
#include <stdio.h> int main() { printf("%4d%4d%4d\n",4|6,5&7,8^9); }