#include <iostream>
#include <cstdint>
using namespace std;
struct Status {
union {
uint16_t code;
struct {
uint8_t low;
uint8_t high;
};
};
bool ok;
};
int main() {
uint16_t c;
cin >> c;
Status s;
s.code = c;
s.ok = (s.code == 0);
cout << "low=" << (int)s.low
<< " high=" << (int)s.high
<< " ok=" << (s.ok ? "true" : "false");
return 0;
}
Solution Details
👉 In simple words: It’s like having a short status word that you can read whole (code) or as two bytes (low, high). The ok flag adds a quick validity check.
Significance for Embedded Developers
Input
258
Expected Output
low=2 high=1 ok=false