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
    int output = (n>>k)&1; // the kth bit will become LSB and will be anded with 1.
    if(output ==1) return true;
    else return false;
}

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

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote