#include <stdio.h>
#include <stdint.h>
uint16_t pack_register(uint8_t mode, uint8_t speed, uint8_t status) {
// Your logic here
uint16_t reg;
uint16_t moden=((mode&0x07)<<0);
//printf("%u\n",moden);
uint16_t speedn=((speed&0x1F)<<3);
//printf("%u\n",speedn);
uint16_t statusn=((status&0x3F)<<10);
//printf("%u\n",statusn);
reg|=(moden|speedn|statusn);
return 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;
}Make sure the bits is of the same number of bits as mentioned and then shift the bits accordingly and append the bits to a single reg.
Note: While shifting make sure to increase the size of the variable (eg: uint8_t to uint16_t) in order to accomadate the shifted value
Input
3 10 12
Expected Output
12371