#include <stdio.h>
#include <stdint.h>
void decode_status(uint8_t status_reg) {
// Your logic here
const char *bit_to_flag_map[8]={"Power On","Error","Tx Ready","Rx Ready","Overheat","Undervoltage","Timeout","Reserved"};
const char *temp[]={""};
uint8_t reg = status_reg;
uint8_t mask=1;
uint8_t x=0;
for(int i=0;i<8;i++){
status_reg=reg;
reg=reg&mask;
if(1==reg){
temp[x]=bit_to_flag_map[i];
x++;
}
reg=status_reg;
reg=reg>>1;
}
for(int i=0;i<x;i++){
printf("%s",temp[i]);
printf("\n");
}
}
int main() {
uint8_t reg;
scanf("%hhu", ®);
decode_status(reg);
return 0;
}Solving Approach
Input
13
Expected Output
Power On Tx Ready Rx Ready