#include <iostream>
#include <cstdint>
using namespace std;
union Reg {
uint8_t raw;
struct {
unsigned en : 1;
unsigned mode : 3;
unsigned reserved : 4;
} bits;
};
int main() {
int val;
cin >> val;
Reg r;
r.raw = val;
cout << "en=" << r.bits.en << " mode=" << r.bits.mode;
return 0;
}
Solution Details
👉 In simple words: It’s like having two ways to look at the same register — one as a single 8-bit number, another as named fields.
Significance for Embedded Developers
Still lets you read/write the whole register via raw when needed.
Input
13
Expected Output
en=1 mode=6