#include <stdio.h> int main() { unsigned int regValue; // Register value (0-255) int bitPos, mode; // Input: register value, bit position, and mode scanf("%u %d %d", ®Value, &bitPos, &mode); // Ensure values are within valid range if (regValue > 255 || bitPos < 0 || bitPos > 7 || (mode != 0 && mode != 1)) { printf("Invalid input\n"); return 1; } if (mode == 1) { // Set the bit regValue |= (1 << bitPos); } else { // Clear the bit regValue &= ~(1 << bitPos); } // Print updated register value printf("%u\n", regValue); return 0; }
Test Cases
Test Results
Input
10 3 1
Expected Output
10