Set Baud Rate Field in Control Register

Code

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

#define BAUD_POS    8U

uint32_t set_baud_rate(uint32_t reg, uint8_t baud) {
    // Your code here
    uint32_t mask=0;
    mask = (0x0F<<BAUD_POS);
    reg &= ~(mask); //Clear the baud bits in the register
    reg |= (baud<<BAUD_POS);// Set the baud bits with given value
    return reg;
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

0 10

Expected Output

2560