All submissions

Code

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

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

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

Solving Approach

Find th eposition value of th ebit and bitwise AND it with register.

result is zero if bit was 0, else it was set

 

 

Loading...

Input

4 2

Expected Output

1