All submissions

Extract and Modify Field in a 32-bit Register

 

#include <stdio.h>
#include <stdint.h>

uint32_t update_register(uint32_t reg) {
    // Your logic here
    // Extract the 5-bit field at positions 10-14
    uint32_t field = (reg >> 10) & 0x1F;

    // If less than 31, increment it by 1
    if (field < 31) 
        field++;

    // Clear bits 10-14 in reg
    reg &= ~(0x1F << 10);

    // return the updated field back to bits 10-14
   return (reg |= (field << 10));

}

int main() {
    uint32_t reg;
    scanf("%u", &reg);
    uint32_t updated = update_register(reg);
    printf("%u", updated);
    return 0;
}

 

 

 

Loading...

Input

15360

Expected Output

16384