All submissions

Validate Configuration Register Layout

Code

#include <stdio.h>

typedef struct {
    unsigned short reg;
} ConfigRegister;

#define ENABLE_ON_BIT 0
#define PRIORITY_INVALID_MASK 3
#define RESERVED_START_BIT 4

int validate_config(ConfigRegister *cfg) {
    // Write logic using pointer access
    unsigned short val = cfg->reg;
    if (val & 1)
    {
        val>>=2;
        if((val & PRIORITY_INVALID_MASK) < PRIORITY_INVALID_MASK)
        {
            val>>=2;
            if(!val)
            {
               return 1; 
            }
            
        }
        
    }
    return 0;
}

int main() {
    ConfigRegister cfg;
    scanf("%hx", &cfg.reg);

    int result = validate_config(&cfg);
    printf("%d", result);

    return 0;
}

Solving Approach

 

 

 

Loading...

Input

0005

Expected Output

1