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