Set Baud Rate Field in Control Register

 

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

uint32_t set_baud_rate(uint32_t reg, uint8_t baud) {
    // Your code here
    // Clear bits 8 to 11 in the register
    reg &= ~(0xF << 8);  // 0xF = 0b1111, shifted to bits 8–11 and inverted

    // Set new baud value at bits 8 to 11
    reg |= ((baud & 0xF) << 8);  // Mask baud to 4 bits and shift into position

    return reg;
}

int main() {
    uint32_t reg;
    uint8_t baud;
    scanf("%u %hhu", &reg, &baud);
    printf("%u", set_baud_rate(reg, baud));
    return 0;
}

 

 

 

 

Loading...

Input

0 10

Expected Output

2560