All submissions

Code

#include <stdio.h>
#include <stdint.h>

uint8_t is_bit_set(uint8_t reg, uint8_t pos) {
    // Your code here
    uint8_t ret_val =0;
    uint8_t val = (1<<pos);
    
    // If AND operation of n and 
    // value is non-zero, it means
    // k'th bit is set 
    if ((reg&val) != 0) {
       ret_val =1;
    } 
    return ret_val;

}

int main() {
    uint8_t reg, pos;
    scanf("%hhu %hhu", &reg, &pos);
    printf("%u", is_bit_set(reg, pos));
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

4 2

Expected Output

1