3. Check if K-th Bit is Set

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>

int main() {
    int N, K;

    // Input
    scanf("%d %d", &N, &K);

    // Check K-th bit
    if ((N >> K) & 1)
        printf("1");
    else
        printf("0");

    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote