#include <stdio.h>
#include <stdint.h>
#define MASK(BITS) ((1U << BITS)-1)
#define SHIFTED_MASK(POS, BITS) ((MASK(BITS)) << POS)
#define CLEAR_BITS(REG, POS, BITS) \
((REG) &= ~SHIFTED_MASK(POS, BITS))
#define SET_BITS(REG, POS, BITS, VAL) \
((REG) = ((REG) & ~SHIFTED_MASK(POS, BITS)) | (((VAL) & MASK(BITS)) << (POS)) )
#define GET_BITS(REG, POS, BITS) \
(((REG) >> (POS)) & MASK(BITS))
uint32_t update_register(uint32_t reg) {
// Your logic here
uint8_t val = (uint8_t) GET_BITS(reg, 10, 5);
if(val < 31)
{
val++;
}
SET_BITS(reg, 10, 5, val);
return reg;
}
int main() {
uint32_t reg;
scanf("%u", ®);
uint32_t updated = update_register(reg);
printf("%u", updated);
return 0;
}
Input
15360
Expected Output
16384