#include <stdio.h>
#include <stdint.h>
uint32_t replace_field(uint32_t reg, uint32_t val, uint8_t pos, uint8_t len) {
// I think the easiest way to do this is just to clear before setting
uint32_t clear_mask = (1 << len) - 1;
clear_mask <<= pos;
reg &= ~(clear_mask);
// You can just or val (as long as the val is in the correct spot and
// the rest of the bits are 0)
val = (val << pos);
return reg | val;
}
int main() {
uint32_t reg, val;
uint8_t pos, len;
scanf("%u %u %hhu %hhu", ®, &val, &pos, &len);
printf("%u", replace_field(reg, val, pos, len));
return 0;
}