Code

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

uint8_t is_bit_set(uint8_t reg, uint8_t pos) {
    // Your code here
    uint8_t SET_VALUE;
    if (reg & (1 << pos))
    {
        SET_VALUE = 1 ;
    }
    if (!(reg & (1 << pos)))
    {
        SET_VALUE = 0;
    }
    return SET_VALUE;
}

int main() {
    uint8_t reg, pos;
    scanf("%hhu %hhu", &reg, &pos);
    printf("%u", is_bit_set(reg, pos));
    return 0;
}

Solving Approach

 

For checking if a bit is set or not , we must use the Bitwise AND operator for checking

reg & (1 << pos)

 

Upvote
Downvote
Loading...

Input

4 2

Expected Output

1