#include <stdio.h>
int isKthBitSet(int n, int k) {
// Write your code here
if(n&(1<<k))
return 1;
else
return 0;
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
printf("%d", isKthBitSet(n, k));
return 0;
}
Solving Approach
You left shift 1 by k (1 << k) to create a mask where only the k-th bit is set.
Example: if k = 3, then 1 << 3 = 1000 (binary).
You perform bitwise AND between n and the mask.
If the k-th bit of n is set, result will be non-zero.
Otherwise, result will be zero.
Based on this, you return 1 if set and 0 if not set.