3. Check if K-th Bit is Set

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>

int isKthBitSet(int n, int k) {
    // Write your code here
    return (((n>>k)&1) == 1);
}

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    printf("%d", isKthBitSet(n, k));
    return 0;
}

Solving Approach

The above problem is similar to the checking bit status of the given number. if the particular bit is 1, then the bit is set, otherwise not set(clear).

 

 

Was this helpful?
Upvote
Downvote