Code

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

uint8_t is_bit_set(uint8_t reg, uint8_t pos) 
{
    return (reg & (1<<pos)) ? 1 :0;

}

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



// Basic c program

// #include<stdio.h>

// int main()
// {
//    int reg ,pos;

//    scanf("%d%d",&reg,&pos);

//    if(reg & (1<<pos))
//    {
//         printf("1");   // bit is SET
//    }
//    else
//    {
//         printf("0");   // bit is CLEAR
//    }

//    return 0;
// }

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

4 2

Expected Output

1