Code

#include <stdio.h>

// Function to check if a bit at a given position is set
int isBitSet(unsigned char reg, int pos) {
    return (reg & (1 << pos)) ? 1 : 0;
    }

    int main() {
        unsigned char reg;
            int pos;

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

                    int result = isBitSet(reg, pos);
                        printf("%d\n", result);

                            return 0;
                            }

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

4 2

Expected Output

1