#include <iostream>
using namespace std;
void show_binary(unsigned int u);
int main()
{
unsigned u = 123;
cout << "Here's the number in binary: ";
show_binary(u);
cout << "Here's the complement of the number: ";
show_binary(~u);
return 0;
}
void show_binary(unsigned int u)
{
int t;
for(t=128; t>0; t = t/2)
if(u & t) cout << "1 ";
else cout << "0 ";
cout << "\n";
}
Here's the number in binary: 0 1 1 1 1 0 1 1
Here's the complement of the number: 1 0 0 0 0 1 0 0