#include #include using namespace std; void PrintAsBinary(short s); int main() { short s; s = 9; cout << s << " = " ; PrintAsBinary(9); cout << endl << endl; s = ~s; cout << "~s = " << s << " = "; PrintAsBinary(s); cout << endl << endl; s = numeric_limits::max(); cout << s << " = " ; PrintAsBinary(s); cout << endl; return 0; } void PrintAsBinary(short s){ int bits{sizeof(s)*8}; int i = 0; unsigned short mask = 1<<(bits-1); while (mask > 0) { if (mask & s) { cout << "1"; } else { cout << "0"; } mask >>= 1; } return; }