#include <stdio.h>
#include <stdint.h>
uint8_t is_bit_set(uint8_t reg, uint8_t pos) {
// we can check if a bit is set by ANDing it with 1
// left shift 1 by <pos> bits, then AND it with reg
// right shift the result by pos bits
return (reg & (1 << pos)) >> pos;
}
int main() {
uint8_t reg, pos;
scanf("%hhu %hhu", ®, &pos);
printf("%u", is_bit_set(reg, pos));
return 0;
}
Input
4 2
Expected Output
1