//demonstration of bit manipulation
#include "printBinary.h"
#include <iostream>
usingnamespace std;
#define PR(STR, EXPR) \
cout << STR; printBinary(EXPR); cout << endl;
int main()
{
unsignedint getval;
unsignedchar a, b;
cout << "Enter a number between 0 and 255: ";
cin >> getval; a = getval;
PR("a in binary: ", a);
cout << "Enter a number between 0 and 255: ";
cin >> getval; b = getval;
PR("b in binary: ", b);
PR("a | b = ", a | b);
PR("a & b = ", a & b);
PR("a ^ b = ", a ^ b);
PR("~a = ", ~a);
PR("~b = ", ~b);
//an interesting bit pattern
unsignedchar c = 0x5A;
PR("c in binary: ", c);
a |= c;
PR("a |= c; a = ", a);
b &= c;
PR("b &= c; b = ", b);
b ^= a;
PR("b ^= a; b= ", b);
}
1 2 3
//display a byte in binary
//printBinary.h
void printBinary(constunsignedchar val);
the code above produces Error 1 error LNK2019: unresolved external symbol "void __cdecl printBinary(unsigned char)" (?printBinary@@YAXE@Z) referenced in function _main main.obj Bitwise