Showing posts with label k. Find if kth bit is set or not using bitwise right shift operator. Show all posts
Showing posts with label k. Find if kth bit is set or not using bitwise right shift operator. Show all posts

Monday, 14 October 2019

Given 2 integers a,k. Find if kth bit is set or not using bitwise right shift operator

//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);
}