All submissions

Check if K-th Bit is Set

Hmm Code

#include <stdio.h>

int isKthBitSet(int n, int k) {
    return ( ((n>>k) & 1)? 1 : 0 );
}

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

Solving Approach

Shift the reg to make that particular bit to be first and then compare it to 1 and accordingly answer in 1 and 0.

 

 

Loading...

Input

8 3

Expected Output

1