// p03_07.cpp: Storing four nonnegative integers of four bits
// in a short int
#include <iostream>
using namespace std;

int main() {
int a0, a1, a2, a3, i;
short int x;
cout << "Enter four nonnegative integers "
        "a0, a1, a2, and a3,\n"
        "each less than 16:\n";
cin >> a0 >> a1 >> a2 >> a3;
x = a3 << 12 | a2 << 8 | a1 << 4 | a0;
cout << "Enter 0, 1,2, or 3 to retrieve the first,\n"
        "second, third, or fourth of these integers:\n";
cin >> i;
int nShift = 4*i;
int ai = (static_cast<unsigned int>(x) >> nShift) & 0xF;
cout << "Retrieved: " << ai << endl;
return 0;
}
