Check if K-th Bit is Set

Code

#include <stdio.h>



int main() 
{
    int n, k;
    scanf("%d %d", &n, &k);
    

    if(n & (1<< k))
    {
        printf("1");
    }
    else
    {
        printf("0");
    }
    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8 3

Expected Output

1