3. Check if K-th Bit is Set

Back To All Submissions
Previous Submission
Next Submission

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

 

 

 

Was this helpful?
Upvote
Downvote