#include <stdio.h>
#include <stdint.h>
void aff0(){printf("Power On\n");}
void aff1(){printf("Error\n");}
void aff2(){printf("Tx Ready\n");}
void aff3(){printf("Rx Ready\n");}
void aff4(){printf("Overheat\n");}
void aff5(){printf("Undervoltage\n");}
void aff6(){printf("Timeout\n");}
void aff7(){printf("Reserved\n");}
void decode_status(uint8_t status_reg) {
// Your logic here
void (* aff[8]) (){
&aff0, &aff1, &aff2, &aff3, &aff4, &aff5, &aff6, &aff7
};
for(int i = 0; i < 8; i++){
if(((1 << i) & status_reg) > 0 ){
aff[i]();
}
}
}
int main() {
uint8_t reg;
scanf("%hhu", ®);
decode_status(reg);
return 0;
}
Solving Approach
Input
13
Expected Output
Power On Tx Ready Rx Ready