#include <stdio.h> #include <stdint.h> uint8_t is_bit_set(uint8_t reg, uint8_t pos) { if(reg&(1<<pos)) return 1; else return 0; } int main() { uint8_t reg, pos; scanf("%hhu %hhu", ®, &pos); printf("%u", is_bit_set(reg, pos)); return 0; }
if(reg&(1<<pos);
here & operator compares each digit if same position 1 otherwise 0
return 1;
else
return 0;
Test Cases
Test Results
Input
4 2
Expected Output
1