Check if K-th Bit is Set

Code

#include <stdio.h>
#include <stdbool.h>
int isKthBitSet(int n, int k) 
{
    int bitMask = 1 << k;
    if(n & bitMask)
        return true;

    return false;
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8 3

Expected Output

1