#include <stdio.h>
#include <stdint.h>
uint32_t replace_field(uint32_t reg, uint32_t val, uint8_t pos, uint8_t len) {
// Your code here
uint32_t mask = ~0U; // all ones
mask <<= len; // inserted zeros from beggining to len
mask = ~mask; // negate now we have 1s from beginning to len
mask <<= pos; // move the 1s pos times so we get on the alligned target area all ones rest zeros
val <<= pos; // allign val with reg
reg = (reg & ~mask) | val; // make reg as it is except in target area it becomes zeros since we negated mask first then or it with val to change this area
return reg;
}
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;
}