#include <stdio.h> #include <stdint.h> uint8_t is_bit_set(uint8_t reg, uint8_t pos) { int mask=1; int copy=reg | mask<<pos;//0000 0100 | 0000 0100 = 0000 0100 if(reg==copy) return 1; else return 0; // 0000 0100 | 0000 0010 =0000 0110 // 1111 1111 | 0000 0111 =1111 1111 } int main() { uint8_t reg, pos; scanf("%hhu %hhu", ®, &pos); printf("%u", is_bit_set(reg, pos)); return 0; }
Test Cases
Test Results
Input
4 2
Expected Output
1