#include <stdio.h>
#include <stdint.h>
#define STATUS_POWER_ON (1 << 0)
#define STATUS_ERROR (1 << 1)
#define STATUS_TX_READY (1 << 2)
#define STATUS_RX_READY (1 << 3)
#define STATUS_OVERHEAT (1 << 4)
#define STATUS_UNDERVOLTAGE (1 << 5)
#define STATUS_TIMEOUT (1 << 6)
#define STATUS_RESERVED (1 << 7)
void decode_status(uint8_t status_reg) {
if (status_reg & STATUS_POWER_ON) { printf("Power On\n"); }
if (status_reg & STATUS_ERROR) { printf("Error\n"); }
if (status_reg & STATUS_TX_READY) { printf("Tx Ready\n"); }
if (status_reg & STATUS_RX_READY) { printf("Rx Ready\n"); }
if (status_reg & STATUS_OVERHEAT) { printf("Overheat\n"); }
if (status_reg & STATUS_UNDERVOLTAGE) { printf("Undervoltage\n"); }
if (status_reg & STATUS_TIMEOUT) { printf("Timeout\n"); }
if (status_reg & STATUS_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