#include <stdio.h>
typedef union {
unsigned char reg;
struct {
unsigned char enable : 1;
unsigned char mode : 1;
unsigned char priority : 2;
unsigned char reserved : 4;
} bits;
} ControlRegister;
// Write your logic here
int validate_register(ControlRegister *ctrl) {
unsigned char temp = *(unsigned char*)ctrl;
if (((temp & 0x01) == 1) && (((temp >> 2) & 0x03) <= 2) && ((temp & 0xF0) == 0)){
return 1;
}
return 0;
}
int main() {
ControlRegister ctrl;
scanf("%hhx", &ctrl.reg);
int result = validate_register(&ctrl);
printf("%d", result);
return 0;
}
Input
05
Expected Output
1