All submissions

Check if K-th Bit is Set

Code

    #include <stdio.h>

    int isKthBitSet(int n, int k) {
        // Write your code here
        int mask = 1 << k;
        // Use AND operation to check if K-th bit is set
        // If result is non-zero, the bit is set (return 1)
        // If result is zero, the bit is not set (return 0)
    return (n & mask) != 0 ? 1 : 0;
    }

    int main() {
        int n, k;
        scanf("%d %d", &n, &k);
        printf("%d", isKthBitSet(n, k));
        return 0;
    }

Solving Approach

 

 

 

Loading...

Input

8 3

Expected Output

1