#include <stdio.h> #include <stdint.h> // Define macros here #define ENABLE_POS 0 #define MODE_POS 1 #define SPEED_POS 3 #define SET_ENABLE(x) ((uint16_t)((x & 0x1) << ENABLE_POS)) #define SET_MODE(x) ((uint16_t)((x & 0x3) << MODE_POS)) #define SET_SPEED(x) ((uint16_t)((x & 0x7) << SPEED_POS)) uint16_t build_register(uint8_t enable, uint8_t mode, uint8_t speed) { // Use macros to set fields uint16_t res = 0; res |= SET_ENABLE(enable); res |= SET_MODE(mode); res |= SET_SPEED(speed); return res; } int main() { uint8_t enable, mode, speed; scanf("%hhu %hhu %hhu", &enable, &mode, &speed); uint16_t reg = build_register(enable, mode, speed); printf("%u", reg); return 0; }
Test Cases
Test Results
Input
1 2 4
Expected Output
37