All submissions

Set the Bit in an 8-bit Register

Code

#include <stdio.h>

// Function to set bit at given position
unsigned char setBit(unsigned char reg, int pos) {
    return reg | (1 << pos); // Set bit using OR
}

int main() {
    unsigned char reg;
    int pos;
    
    scanf("%hhu %d", &reg, &pos);  // input register value and bit position
    printf("%d", setBit(reg, pos));
    
    return 0;
}

Solving Approach
 

 

 

Loading...

Input

5 1

Expected Output

7