#include <stdio.h>
#include <stdint.h>
#define POWER_ON (1 << 0)
#define ERROR (1 << 1)
#define TX_READY (1 << 2)
#define RX_READY (1 << 3)
#define OVERHEAT (1 << 4)
#define UNDERVOLTAGE (1 << 5)
#define TIMEOUT (1 << 6)
#define RESERVED (1 << 7)
void decode_status(uint8_t status_reg) {
// Your logic here
if(status_reg & POWER_ON) printf("Power On\n");
if(status_reg & ERROR) printf("Error\n");
if(status_reg & TX_READY) printf("Tx Ready\n");
if(status_reg & RX_READY) printf("Rx Ready\n");
if(status_reg & OVERHEAT) printf("Overheat\n");
if(status_reg & UNDERVOLTAGE) printf("Undervoltage\n");
if(status_reg & TIMEOUT) printf("Timeout\n");
if(status_reg & RESERVED) printf("Reserved\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