Set Baud Rate Field in Control Register

Code

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

uint32_t update_baudRate(uint32_t reg_uart, uint8_t new_baudRate){
    reg_uart &= ~(0b1111 << 8); 
    reg_uart = reg_uart | (new_baudRate << 8); 
    return reg_uart; 
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

0 10

Expected Output

2560