All submissions

Code

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

uint8_t is_bit_set(uint8_t reg, uint8_t pos) {
    // Your code here
    return reg>>pos&1?1:0;
}

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

Solving Approach

 

consider example 1.

Input: reg = 0b00000100, pos = 2 
Output: 1

return reg>>pos&1?1:0;

  1. reg>>pos&1 --> here i am checking bit set or not

    1. reg>>pos  --> here i am right shifting for checking position.

    2. &1  --> here i am  and operation between  (a & 1)   a -->  reg>>pos

  2. if it is set it will return true(1).

  3. else it will return false(0).

Loading...

Input

4 2

Expected Output

1