#include <stdio.h> #include <stdint.h> uint8_t is_bit_set(uint8_t reg, uint8_t pos) { // Your code here if(reg &= (1<<pos)){ return 1; } return 0; } int main() { uint8_t reg, pos; scanf("%hhu %hhu", ®, &pos); printf("%u", is_bit_set(reg, pos)); return 0; }
To check a bit, AND it with 1, while also making sure to AND the rest with 0, so that you end up with either value 0 or a value greater than 1.
Test Cases
Test Results
Input
4 2
Expected Output
1