#include <stdio.h> int isKthBitSet(int n, int k) { // Write your code here /*int n_n=n; n &= ~(1<<k); if(n_n == n){ return 0; } else{ return 1; } */ return (n & (1<<k)) ? 1 : 0; } int main() { int n, k; scanf("%d %d", &n, &k); printf("%d", isKthBitSet(n, k)); return 0; }
Solved by copying an bit and set the nth bit and the compare with original
return (n & (1<<k)) ? 1 : 0;
Test Cases
Test Results
Input
8 3
Expected Output
1