#include <stdio.h> typedef struct { unsigned short reg; } ConfigRegister; int select_bits(int data, int start, int end) { int mask = (1 << (end - start + 1)) - 1; return (data >> start) & mask; } int validate_config(ConfigRegister *cfg) { return select_bits(cfg->reg, 0, 0) == 1 && (select_bits(cfg->reg, 2, 3) != 0b11) && select_bits(cfg->reg, 4, 15) == 0; } int main() { ConfigRegister cfg; scanf("%hx", &cfg.reg); int result = validate_config(&cfg); printf("%d", result); return 0; }
Test Cases
Test Results
Input
0005
Expected Output
1