All submissions

Set or Clear a Specific Bit in a Register

Code

#include <stdio.h>

int main() {
    unsigned int reg, pos, mode;

        // Input: Register value, bit position, operation mode
            scanf("%u %u %u", &reg, &pos, &mode);

                if (mode == 1)
                        reg |= (1 << pos);   // Set the bit
                            else
                                    reg &= ~(1 << pos);  // Clear the bit

                                        printf("%u\n", reg);     // Output the modified register value
                                            return 0;
                                            }

 

 

 

 

Loading...

Input

10 3 1

Expected Output

10