All submissions

Validate Configuration Register Layout

Easy and Simple Approach to solve this problem

Here We are checking two conditions:
1. if the bits from 4-15 are 0's and the bit 0 is 1
2.if the bits 2-3 are not 11

Code

#include <stdio.h>

typedef struct {
    unsigned short reg;
} ConfigRegister;

int validate_config(ConfigRegister *cfg) {+

    /*Here We are checking two conditions
    1. if the bits from 4-15 are 0's and the bit 0 is 1
    2.if the bits 2-3 are not 11*/

    if(((cfg->reg & 0xFFF1)==1) && ((cfg->reg & 6)!= 6)) return 1;
    return 0;
}

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

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

    return 0;
}

 

 

 

 

Loading...

Input

0005

Expected Output

1