lesson 4

// BitTest – initialize two variables and output the
//           results of applying the ~,& , | and ^
//           operations
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
// set output format to hexadecimal
cout.unsetf(cout.dec);
cout.setf(cout.hex);

// initialize two arguments
int nArg1;
nArg1 = 0x1234;

int nArg2;
nArg2 = 0x00ff;

// now perform each operation in turn
// first the unary NOT operator
cout << “Arg1          = 0x” << nArg1 << “\n”;
cout << “Arg2          = 0x” << nArg2 << “\n”;
cout << “~nArg1        = 0x” << ~nArg1 << “\n”;
cout << “~nArg2        = 0x” << ~nArg2 << “\n”;

// now the binary operators
cout << “nArg1 & nArg2 = 0x”
<< (nArg1 & nArg2)
<< “\n”;
cout << “nArg1 | nArg2 = 0x”
<< (nArg1 | nArg2)
<< “\n”;
cout << “nArg1 ^ nArg2 = 0x”
<< (nArg1 ^ nArg2)
<< “\n”;

// wait until user is ready before terminating program
// to allow the user to see the program results
system(“PAUSE”);
return 0;
}

Advertisements

~ by infamouskiller on July 21, 2008.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: