Code

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


/*
int checkbit(uint8_t reg, uint8_t position)
{
    if (reg & (1<<position))
    {
        reg = 1;
    }

    else
    {
        reg = 0;
    }

    return reg;
}


int main()
{
    uint8_t reg;
    uint8_t position;
    scanf("%hhu,%hhu",&reg,&position);

    uint32_t result = checkbit(reg,position);

    printf("%u",result);
    
    return 0;
}
*/


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

uint8_t is_bit_set(uint8_t reg, uint8_t pos) {
    // Your code here
    if (reg & (1<<pos))
    {
        reg = 1;
    }

    else
    {
        reg = 0;
    }
    return reg;
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

4 2

Expected Output

1