By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

Problem with bitwise operators

P: n/a
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!!!!

Dec 24 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
<< 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

Dec 24 '05 #2

P: n/a
Great!!! It works now!!! Thanks!!!!!!

Dec 25 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.