#include <stdio.h>
int isKthBitSet(int n, int k) {
// Write your code here
return (n>>k) & 1;
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
printf("%d", isKthBitSet(n, k));
return 0;
}
The idea is to shift the kth bit to the LSB and then AND with it 1, to check if the resultant is 0 or 1;
if the result is 1(its been ANDed with 1, the original kth bit) and opposite for the kth bit being 0;
now optimized!
Input
8 3
Expected Output
1