#include <stdio.h>
#include <stdint.h>
#define MODE_SIZE 3
#define SPEED_SIZE 5
#define STATUS_SIZE 6
#define MODE_POS 0
#define SPEED_POS 3
#define STATUS_POS 10
volatile uint16_t control_reg = 0; //Precaution ! reg may be writtenfrom anyhere: ISR/DMA/MemoryPins
uint16_t pack_register(uint8_t mode, uint8_t speed, uint8_t status) {
// Your logic here
control_reg |= ((mode & ((1 << MODE_SIZE) - 1)) << MODE_POS);
control_reg |= ((speed & ((1 << SPEED_SIZE) - 1)) << SPEED_POS);
control_reg |= ((status & ((1 << STATUS_SIZE) - 1)) << STATUS_POS);
return control_reg;
}
int main() {
uint8_t mode, speed, status;
scanf("%hhu %hhu %hhu", &mode, &speed, &status);
uint16_t reg = pack_register(mode, speed, status);
printf("%u", reg);
return 0;
}
Input
3 10 12
Expected Output
12371