#include <stdio.h> #include <stdint.h> typedef union { struct { uint16_t adc_value : 12; uint16_t channel : 4; }adc_struct; uint16_t adc_reg; } ADC_Result; int main() { uint16_t reg; scanf("%hx", ®); ADC_Result res; res.adc_reg = reg; printf("Channel: %d\n",res.adc_struct.channel); printf("ADC Value: %d\n",res.adc_struct.adc_value); return 0; }
Test Cases
Test Results
Input
0xC3F5
Expected Output
Channel: 12 ADC Value: 1013