All submissions

Decode Status Register into Human-Readable Flags

Code

#include <stdio.h>
#include <stdint.h>

void decode_status(uint8_t status_reg) {
    // Your logic here
    int x = 0;
    while(1)
    {
        //scan values if it is on
        if (status_reg & (1 << x))
        {
            if (x == 0) printf("Power On\n");
            if (x == 1) printf("Error\n");
            if (x == 2) printf("Tx Ready\n");
            if (x == 3) printf("Rx Ready\n");
            if (x == 4) printf("Overheat\n");
            if (x == 5) printf("Undervoltage\n");
            if (x == 6) printf("Timeout\n");
            if (x == 7) printf("Reserved\n");
        }
        x++;

        if (x == 8)
        {
            break;
        }
    }
}

int main() {
    uint8_t reg;
    scanf("%hhu", &reg);
    decode_status(reg);
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

13

Expected Output

Power On Tx Ready Rx Ready