#include #include using namespace std; const int SIZE = 8; // print a number out in binary form. void BitPrint( unsigned int a) { unsigned int msb = 1<<(SIZE-1); while (msb > 0) { if (msb & a) { cout << 1; } else { cout <<0; } msb /=2; } return; } void AndEm(unsigned int a,unsigned int b) { unsigned int ans = a&b; cout << " "; BitPrint(a); cout << " "<< setw(SIZE) << a << endl; cout << "& " ; BitPrint(b) ; cout << " & " << setw(SIZE) << b << endl; cout << setfill('-'); cout << " " ; cout << setw(SIZE) << "-" << " " << setw(SIZE) << "-" << endl; cout << setfill(' '); cout << " " ; BitPrint(ans); cout << " " << setw(SIZE) << ans << endl; cout << endl; return; } // or two ints and print the corresponding equations. void OrEm(unsigned int a,unsigned int b) { unsigned int ans = a|b; // print in binary form cout << " "; BitPrint(a); cout << " "<< setw(SIZE) << a << endl; cout << "| " ; BitPrint(b) ; cout << " | " << setw(SIZE) << b << endl; cout << setfill('-'); cout << " " ; cout << setw(SIZE) << "-" << " " << setw(SIZE) << "-" << endl; cout << setfill(' '); cout << " " ; BitPrint(ans); cout << " " << setw(SIZE) << ans << endl; cout << endl; return; } int main() { unsigned int bits[SIZE]; unsigned int a; int i; bits[0] = 1; for(i=1; i < SIZE; i++) { bits[i] = bits[i-1]*2; } for(i=0;i