Problem with bitwise operators

P

Protoman

I'm trying to print some values and I get "invalid operand" errors when
I compile; here's my code:

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
int i=0xA;
int j=0xB;
int k=i<<j;
int l=i>>j;
int m=j<<i;
int n=j>>i;
cout << "10&11 : " << i&j << endl;
cout << "10|11 : " << i|j << endl;
cout << "10^11 : " << i^j << endl;
cout << "10<<11: " << k << endl;
cout << "10>>11: " << l << endl;
cout << "11<<10: " << m << endl;
cout << "11>>10: " << n << endl;
cout << "~10 : " << ~i << endl;
cout << "~11 : " << ~j << endl;
system("PAUSE");
return 0;
}

Any suggestions? I have no idea what's wrong. Thanks!!!!
 
S

srinivas

<< has higher priority than logical bitwise operator.
do the following....it works fine.

cout << "10&11 : " << (i&j) << endl;
cout << "10|11 : " << (i|j) << endl;
cout << "10^11 : " << (i^j) << endl;

srinivas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top