#include <stdio.h> #include <stdint.h> #define BAUD_POS_IN_UART_CTRL_REG 8 uint32_t set_baud_rate(uint32_t reg, uint8_t baud) { // Prepare mask to clear all bits from pos 8 to 11 (0-indexed) uint32_t baud_clear_mask = ~(0xF << BAUD_POS_IN_UART_CTRL_REG); reg &= baud_clear_mask; // set new baud in reg reg |= (baud << BAUD_POS_IN_UART_CTRL_REG); return reg; } int main() { uint32_t reg; uint8_t baud; scanf("%u %hhu", ®, &baud); printf("%u", set_baud_rate(reg, baud)); return 0; }
Test Cases
Test Results
Input
0 10
Expected Output
2560