#include <stdio.h>
int isKthBitSet(int n, int k) {
int tmp;
tmp = n & (1 << k);
return (tmp >> k) & 1;
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
printf("%d", isKthBitSet(n, k));
return 0;
}
Solving Approach
We can check bit value at the Kth position by using AND operator with a bitmask at the k-th bit.