All submissions

Set Baud Rate Field in Control Register

Code

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

uint32_t set_baud_rate(uint32_t reg, uint8_t baud) {
    //Step 1 : Clear the bits from 8-11
    reg &= ~(0xF << 8);

    //Step 2 : Set the 8-11 bits of baud rate
    reg |= baud << 8;

    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