1. read a number x
2. rad the position n
3. To get the nth bit of x right shift x by n times. Then perform bitwise AND with 1 i.e. bitStatus = (x >> n) & 1;.
Program
#include<stdio.h>
int main() {
int n,x,status;
scanf("%d%d",&x,&n);
status = (x >> n) & 1;
printf("status is %d",status);
}
Input:
8 2
Output
status is 0
2. rad the position n
3. To get the nth bit of x right shift x by n times. Then perform bitwise AND with 1 i.e. bitStatus = (x >> n) & 1;.
Program
#include<stdio.h>
int main() {
int n,x,status;
scanf("%d%d",&x,&n);
status = (x >> n) & 1;
printf("status is %d",status);
}
Input:
8 2
Output
status is 0
No comments:
Post a Comment