With reference to my previous question, How can i implement AND and OR operations in c++
My next question is, Sometimes it outputs some weird numbers for example 110010 & 010101 = 110591. Why does that happen?
#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;
}
For the question — how to input binary numbers instead of decimal.
You can read them as strings, and then convert them assuming that they are base 2.
So, code like this (not tested!):