Check if K-th Bit is Set

Code

#include <stdio.h>

int set_check(int n, int k) { return (n & (1 << k)) ? 1 : 0; }

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8 3

Expected Output

1