#include <stdio.h> #include <stdint.h> uint32_t set_baud_rate(uint32_t reg, uint8_t baud) { // Your code here uint32_t clear_mask = (~(((1 << 4)-1u) << 8 )) & reg ; reg= clear_mask | (baud << 8); return reg ; } int main() { uint32_t reg; uint8_t baud; scanf("%u %hhu", ®, &baud); printf("%u", set_baud_rate(reg, baud)); return 0; }
creating mask and clearning bit 11:8 in the given register and then inserting the baud rate bits in 11:8
Test Cases
Test Results
Input
0 10
Expected Output
2560