#include <stdio.h>
#include <stdint.h>
typedef union{
uint8_t reg;
struct{
uint8_t power_on : 1;
uint8_t error : 1;
uint8_t tx_ready : 1;
uint8_t rx_ready : 1;
uint8_t overheat : 1;
uint8_t under_voltage : 1;
uint8_t time_out : 1;
uint8_t reserved :1;
}status_regis;
}status_reg_u;
void decode_status(status_reg_u status_reg) {
// Your logic here
if(status_reg.status_regis.power_on){
printf("Power On\n");
}
if(status_reg.status_regis.error){
printf("Error\n");
}
if(status_reg.status_regis.tx_ready){
printf("Tx Ready\n");
}
if(status_reg.status_regis.rx_ready){
printf("Rx Ready\n");
}
if(status_reg.status_regis.overheat){
printf("Overheat\n");
}
if(status_reg.status_regis.under_voltage){
printf("Undervoltage\n");
}
if(status_reg.status_regis.time_out){
printf("Timeout\n");
}
if(status_reg.status_regis.reserved){
printf("Reserved\n");
}
//switch(status_reg.status_reg_t)
}
int main() {
//uint8_t reg;
status_reg_u status_register;
scanf("%hhu", &status_register.reg);
decode_status(status_register);
return 0;
}Solving Approach
Input
13
Expected Output
Power On Tx Ready Rx Ready