#include <stdio.h> #include <stdint.h> #define BIT_PRINT(r, b, s) if(r & (1 << b)) printf("%s\n", s) void decode_status(uint8_t status_reg) { BIT_PRINT(status_reg, 0, "Power On"); BIT_PRINT(status_reg, 1, "Error"); BIT_PRINT(status_reg, 2, "Tx Ready"); BIT_PRINT(status_reg, 3, "Rx Ready"); BIT_PRINT(status_reg, 4, "Overheat"); BIT_PRINT(status_reg, 5, "Undervoltage"); BIT_PRINT(status_reg, 6, "Timeout"); BIT_PRINT(status_reg, 7, "Reserved"); } 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