#include <stdio.h> #include <stdint.h> uint8_t is_bit_set(uint8_t reg, uint8_t pos) { return (reg >> pos) & 1; } int main() { uint8_t reg, pos; scanf("%hhu %hhu", ®, &pos); printf("%u", is_bit_set(reg, pos)); return 0; }
Shift the target bit to the LSB and AND with 1 to get its value.
Test Cases
Test Results
Input
4 2
Expected Output
1