Check if K-th Bit is Set

Code

#include <stdio.h>
#include <stdint.h>

int main(void)
{

    int8_t reg;
    scanf("%hhd", &reg);
    int8_t mask;
    int8_t K;
    scanf("%hhd", &K);
    mask = 1 << K;
    if ((reg & mask) != 0) 
    {
        printf("1\n");
    } else 
    {
        printf("0\n");
    }
    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8 3

Expected Output

1