#include <stdio.h>
#include <stdint.h>
void printPowerOn(){printf("Power On\n");}
void printError(){printf("Error\n");}
void printTxReady(){printf("Tx Ready\n");}
void printRxReady(){printf("Rx Ready\n");}
void printOverHeat(){printf("Overheat\n");}
void printUnderVoltage(){printf("Undervoltage\n");}
void printTimeout(){printf("Timeout\n");}
void printReserved(){printf("Reserved\n");}
typedef void (*PrintFn)();
PrintFn PrintFnArr[]={printPowerOn,printError,printTxReady,printRxReady,printOverHeat,printUnderVoltage,printTimeout,printReserved};
#define GET_BIT(reg,bit) (((reg) >> (bit)) & 1U)
void decode_status(uint8_t status_reg) {
// Your logic here
for(int i=0;i<8;i++)
{
if(GET_BIT(status_reg,i))
{
PrintFnArr[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