#include
#include
using namespace std;
void displayBits( unsigned );
int main()
{
unsigned x;
cout << "Enter an unsigned integer: ";
cin >> x;
displayBits( x );
return 0;
}
void displayBits( unsigned value )
{
unsigned c, displayMask = 1 << 15;
cout << setw( 7 ) << value << " = ";
for ( c = 1; c <= 16; c++ ) {
cout << ( value & displayMask ? '1' : '0' );
value <<= 1;
if ( c % 8 == 0 )
cout << ' ';
}
}