#include <stdio.h> int main() { unsigned char reg_value; int bit_pos, mode; scanf("%hhu %d %d", ®_value, &bit_pos, &mode); if (bit_pos < 0 || bit_pos > 7 || (mode != 0 && mode != 1)) { printf("Invalid input\n"); return 1; } if (mode == 1) { // Set the bit reg_value |= (1 << bit_pos); } else { // Clear the bit reg_value &= ~(1 << bit_pos); } printf("%u\n", reg_value); return 0; }
Test Cases
Test Results
Input
10 3 1
Expected Output
10