#include <stdio.h> // standard input output: scanf, print, unsigned char modifyBit(unsigned char reg, int pos, int mode) { // Write your code here if(mode == 1) { // set bit reg = reg | (1<<pos); } else { // clear bit reg = reg & (~(1<<pos)); } return reg; } // uint: 0 -> 2^n - 1; // int: -2^(n-1) -> 2^(n-1) // char (8bit - 1byte) -> unsigned char = uint8_t int main() { unsigned char reg; // 8-bit int pos, mode; // 4byte - 32bit scanf("%hhu %d %d", ®, &pos, &mode); printf("%d", modifyBit(reg, pos, mode)); return 0; }
Test Cases
Test Results
Input
10 3 1
Expected Output
10