#include <stdio.h> #include <stdint.h> uint8_t is_bit_set(uint8_t reg, uint8_t pos) { // Your code here return (reg & (1<<pos)) >> pos; } int main() { uint8_t reg, pos; scanf("%hhu %hhu", ®, &pos); printf("%u", is_bit_set(reg, pos)); return 0; }
AND the register against the position to leave only that bit, shift the desired bit to right to see if it's value is 0 or 1.
Test Cases
Test Results
Input
4 2
Expected Output
1