All submissions

Code

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

uint8_t is_bit_set(uint8_t reg, uint8_t pos) {
   return (1 & (reg >> pos));
}

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

Solving Approach

use right shift operator ( >>) 

why RIGHT SHIFT OPERATOR

The right shift operator >> is used to "bring down" the bit we are interested in, into the least significant bit (LSB) position.
That way, the result will always be 0 or 1.

 

 

Loading...

Input

4 2

Expected Output

1