Check if K-th Bit is Set

Code

#include <stdio.h>

bool checkBit(unsigned char reg, int pos){
	if(reg & (1<<pos)){
		return 1;
	}
	return 0;
}

int main() {
   char reg;
   int pos;
   scanf("%hhu %d", &reg, &pos);
   printf("%d", checkBit(reg,pos));
   return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8 3

Expected Output

1