I am new to c++ and have had no problems until i got to bitwise logic operations. I compiled the code from a book i have and i can't get it to work right. I can get it to take in two variables but it won't treat them like hex numbers. If i enter someting like 00ff as an argument it won't work. If you can help me thank you very much.
#include <stdio.h>
#include <iostream.h>
int main(int nArg, char* nArgs[])
{
//set output format to hexadecimal
cout.setf(ios::hex);
//input the first argument
int nArg1;
cout << "Enter arg1 as a four-digit hexadecimal: ";
cin >> nArg1;
int nArg2;
cout << "Enter arg2: ";
cin >> nArg2;
cout << "nArg1 & nArg2 = 0x"
<< (nArg1 & nArg2) << "\n";
cout << "nArg1 | nArg2 = 0x"
<< (nArg1 | nArg2) << "\n";
cout << "nArg1 ^ nArg2 = 0x"
<< (nArg1 ^ nArg2) << "\n";
return 0;
}
#include <stdio.h>
#include <iostream.h>
int main(int nArg, char* nArgs[])
{
//set output format to hexadecimal
cout.setf(ios::hex);
//input the first argument
int nArg1;
cout << "Enter arg1 as a four-digit hexadecimal: ";
cin >> nArg1;
int nArg2;
cout << "Enter arg2: ";
cin >> nArg2;
cout << "nArg1 & nArg2 = 0x"
<< (nArg1 & nArg2) << "\n";
cout << "nArg1 | nArg2 = 0x"
<< (nArg1 | nArg2) << "\n";
cout << "nArg1 ^ nArg2 = 0x"
<< (nArg1 ^ nArg2) << "\n";
return 0;
}