#include <stdio.h>
#include <stdint.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;
int validate_register(ControlRegister *ctrl) {
uint8_t validation_sum = 0;
if(ctrl->bits.enable){
validation_sum++;
}
if(ctrl->bits.priority <= 2){
validation_sum++;
}
if(!(ctrl->bits.reserved)){
validation_sum++;
}
return (validation_sum == 3) ? 1 : 0;
}
int main() {
ControlRegister ctrl;
scanf("%hhx", &ctrl.reg);
int result = validate_register(&ctrl);
printf("%d", result);
return 0;
}
Input
05
Expected Output
1