#include <stdio.h>
#include <stdint.h>
#define MODE_POS 0
#define SPEED_POS 3
#define STATUS_POS 10
#define MODE_LEN 3
#define SPEED_LEN 5
#define STATUS_LEN 6
#define MASK_MODE ((1U<<MODE_LEN) - 1)
#define MASK_SPEED ((1U<<SPEED_LEN)-1)
#define MASK_STATUS ((1U<<STATUS_LEN) - 1)
uint16_t pack_register(uint8_t mode, uint8_t speed, uint8_t status) {
// Your logic here
uint16_t pack = 0;
pack |= ((uint16_t)(mode&MASK_MODE)<<MODE_POS);
pack |= ((uint16_t)(speed&MASK_SPEED)<<SPEED_POS);
pack |= ((uint16_t)(status&MASK_STATUS)<<STATUS_POS);
return pack;
}
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