Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 24th, 2005, 11:15 PM
Protoman
Guest
 
Posts: n/a
Default Problem with bitwise operators

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!!!!

  #2  
Old December 24th, 2005, 11:45 PM
srinivas
Guest
 
Posts: n/a
Default Re: Problem with bitwise operators

<< 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

  #3  
Old December 25th, 2005, 01:05 AM
Protoman
Guest
 
Posts: n/a
Default Re: Problem with bitwise operators

Great!!! It works now!!! Thanks!!!!!!

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles