Code

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

uint8_t isKthBitSet(uint8_t n , uint8_t k)
{
    uint8_t SetorNotSet;
    if(n & (1 << k)) // To check if the bit is set or not set 
    {
        SetorNotSet = 1;
        //printf("the bit position %hhu is set\n",k);
    }
    else
    {
        SetorNotSet = 0;
        //printf("the bit position %hhu  is not set\n",k);
    }
    return SetorNotSet;
}


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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8 3

Expected Output

1