Check if K-th Bit is Set

Code

#include<stdio.h>
int checkBit(int N,int K)
{
    if((N & (1 << K)) != 0)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
int main()
{
    int N,K;
    scanf("%d %d",&N,&K);
    printf("%d",checkBit(N,K));
    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8 3

Expected Output

1