#include <iostream> #include <cstdint> using namespace std; // Define a union named ByteSplitter with: // uint16_t word // uint8_t bytes[2] typedef union { uint16_t word; uint8_t bytes [2]; }ByteSplitter; int main() { uint16_t val; cin >> val; ByteSplitter u; u.word = val; cout << "LSB=" << (int)u.bytes[0] << " MSB=" << (int)u.bytes[1]; return 0; }
Test Cases
Test Results
Input
4660
Expected Output
LSB=52 MSB=18