#include <stdio.h>
#include <stdint.h>
void decode_status(uint8_t status_reg) {
// Your logic here
// Array to map bit positions to flag names
const char *flag_names[] =
{
"Power On", // Bit 0
"Error", // Bit 1
"Tx Ready", // Bit 2
"Rx Ready", // Bit 3
"Overheat", // Bit 4
"Undervoltage", // Bit 5
"Timeout", // Bit 6
"Reserved" // Bit 7
};
// Iterate through all 8 bits from LSB to MSB
for (int i = 0; i < 8; i++) // Check if the i-th bit is set
{
if (status_reg & (1U << i))
printf("%s\n", flag_names[i]); // If set, print the corresponding flag name
}
}
int main() {
uint8_t reg;
scanf("%hhu", ®);
decode_status(reg);
return 0;
}
Input
13
Expected Output
Power On Tx Ready Rx Ready