#include <iostream>
using namespace std;
#define WARN(eq, str)\
{\
if (!(eq))\
{\
cout<<"Warning, eq is not satisfied!" << str <<endl;\
}\
}
int main()
{
cout << "Hello Complex Digital World!"<<endl;
// create Complex Number: cAll
int aImg = 8, bReal = 4;
int cAll = ( aImg << 16) | bReal;
cout <<hex << " Img:" << aImg << ", Real: "<< bReal <<", Complex: "<< cAll <<endl;
//Obtain Img,Real from cAll
int cImg, cReal;
cImg = cAll >> 16;
cReal = (cAll << 16) >> 16;
cout << " cAll "<< cAll << ", cImg=" << cImg <<", cReal="<< cReal <<endl;
WARN(cImg == 8, "Imag is not 8");
WARN(cReal==16,"Real is not 16");
return 0;
}
result
Hello Complex Digital World!
Img:8, Real: 4, Complex: 80004
cAll 80004, cImg=8, cReal=4
Warning, eq is not satisfied!Real is not 16