//Given 2 integers a,k. Find if kth bit is set or not using bitwise right shift operator
#include<stdio.h>
int main() {
int a,k,t;
scanf("%d%d",&a,&k);
t=a>>(k-1);
if(t&1 == 0)
printf("%d th bit is not set",k);
else
printf("%dth bit is set",k);
}
#include<stdio.h>
int main() {
int a,k,t;
scanf("%d%d",&a,&k);
t=a>>(k-1);
if(t&1 == 0)
printf("%d th bit is not set",k);
else
printf("%dth bit is set",k);
}
No comments:
Post a Comment