#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; }
Shift the reg to make that particular bit to be first and then compare it to 1 and accordingly answer in 1 and 0.
Test Cases
Test Results
Input
8 3
Expected Output
1