All submissions

Extract and Modify Field in a 32-bit Register

Code

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

typedef union{
    uint32_t four_byte;
    struct{
    unsigned int first_field :10;
    unsigned int target      :5;
    unsigned int reserved    :17;
    }bits;
} Mystruct;

uint32_t update_register(uint32_t reg) {
    // Your logic here
    Mystruct long_reg;
    long_reg.four_byte = reg;
    if(long_reg.bits.target  < 31){
        long_reg.bits.target ++;
    }
    return long_reg.four_byte;
}

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

Solving Approach

 

 

 

Loading...

Input

15360

Expected Output

16384