C++ cout setf(cout.hex) Set output format to hexadecimal
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { // set output format to hexadecimal cout.unsetf(cout.dec);/* w w w. ja va2s . co m*/ cout.setf(cout.hex); // initialize two arguments int nArg1 = 0x78ABCDEF; int nArg2 = 0x12345678; cout << " nArg1 = 0x" << nArg1 << endl; cout << "~nArg1 = 0x" << ~nArg1 << "\n" << endl; cout << " nArg2 = 0x" << nArg2 << endl; cout << "~nArg2 = 0x" << ~nArg2 << "\n" << endl; cout << " 0x" << nArg1 << "\n" << "& 0x" << nArg2 << "\n" << " ----------" << "\n" << " 0x" << (nArg1 & nArg2) << "\n" << endl; cout << " 0x" << nArg1 << "\n" << "| 0x" << nArg2 << "\n" << " ----------" << "\n" << " 0x" << (nArg1 | nArg2) << "\n" << endl; cout << " 0x" << nArg1 << "\n" << "^ 0x" << nArg2 << "\n" << " ----------" << "\n" << " 0x" << (nArg1 ^ nArg2) << "\n" << endl; return 0; }