All submissions

Code

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

uint8_t is_bit_set(uint8_t reg, uint8_t pos) {
    return ((reg & (1 << pos)) != 0) ? 1U : 0U;
}

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

Solving Approach

1 left shift to position will create a mask. While AND operation is performed resulting in 0 in case of bit is cleared and non-zero value in case of bit is set, therefore terinary operator is used to return 1 or 0 respectively.

 

 

Loading...

Input

4 2

Expected Output

1