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;
    scanf("%d %d", &N, &K);

    // Check if K-th bit is set using bitwise AND
    if (N & (1 << K))
        printf("1\n");
    else
        printf("0\n");

    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote