参照我刚才的问题,How can i implement AND and OR operations in c++错误执行“与”和“或” C++
我的下一个问题是,有时候,它输出例如110010 & 010101 = 110591.一些奇怪的号码为什么会发生呢?
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
long int s;
long int l;
long int r;
cin>>s;
cout<<endl;
cin>>l;
cout<<setfill('0')<<setw (5)<<s<<endl<<setfill('0')<<setw (5)<<l<<endl;
r=s|l;
cout<<r<<endl;
return 0;
}
如果你知道他们在做什么,他们不是“怪异的数字”;) – Marlon 2011-06-06 01:32:08
请发布你使用的代码,因为这些数字没有意义。对于正数* x *和* y *,* z * = * x *&* y *,* z *不能大于* x *且* z *不能大于* y *。 – 2011-06-06 01:33:33
// setw example #include #include using namespace std; int main(){ long int s; long int l; long int r; cin >> s; cout << endl; cin >> l; (5)<< s << endl << setfill('0')<< setw(5)<< l << endl; r = s | l; cout << r << endl; return 0; } –
Shadi
2011-06-06 01:36:06