#include <stdio.h>
#include <stdint.h>
#define EN 0
#define MODE 1
#define SPEED 3
#define RES 5
// Define macros here
#define SET_ENABLE(x) ((x & 0x01) << 0) // Only 1 bit
#define SET_MODE(x) ((x & 0x03) << 1) // Only 2 bits
#define SET_SPEED(x) ((x & 0x07) << 3) // Only 3 bits
uint16_t build_register(uint8_t enable, uint8_t mode, uint8_t speed) {
// Use macros to set fields
uint16_t reg =0x00;
reg|=SET_ENABLE(enable);
reg|=SET_MODE(mode);
reg|=SET_SPEED(speed);
return reg;
}
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;
}
Input
1 2 4
Expected Output
37