All submissions

Clear the Bit in an 8-bit Register

Code

#include <stdio.h>
#include <stdint.h>

// Function to clear (set to 0) a specific bit
uint8_t clearBit(uint8_t reg, int pos) {
    return reg & ~(1 << pos);
}

int main() {
    uint8_t reg;
    int pos;

    scanf("%hhu %d", &reg, &pos);

    if (pos < 0 || pos > 7) {
        printf("Invalid bit position\n");
        return 1;
    }

    uint8_t result = clearBit(reg, pos);
    printf("%u\n", result);

    return 0;
}

Solving Approach

 

 

 

Loading...

Input

7 0

Expected Output

6