#include <iostream> #include <iomanip> #include <cstdint> using namespace std; // your code here: define struct AdcSample with timestamp and anonymous union struct AdcSample { uint32_t timestamp; union { uint16_t raw; struct { uint8_t lo; uint8_t hi; }; }; }; int main() { uint32_t ts; uint16_t raw; cin >> ts >> std::hex >> raw; AdcSample sample; sample.timestamp = ts; sample.raw = raw; cout << "ts=" << sample.timestamp << " lo=0x" << hex << uppercase << (int)sample.lo << " hi=0x" << hex << uppercase << (int)sample.hi; return 0; }
Test Cases
Test Results
Input
1000 0x03F2
Expected Output
ts=1000 lo=0xF2 hi=0x3