26. WAP to know whether a bit is high or low.

 

#include <stdio.h>

void main()

{

    // Method 1

    int num,pos,r;

    printf("Enter the number : ");

    scanf("%d",&num);

    printf("Enter the position : ");

    scanf("%d",&pos);

    r=num&1<<pos;

    printf("The %dth position of number %d is %d\n",pos,num,r);

 

    // Method 2

    int num,pos,r;

    printf("Enter the number : ");

    scanf("%d",&num);

    printf("Enter the position : ");

    scanf("%d",&pos);

    r=num>>pos&1;

    printf("The %dth position of number %d is %d\n",pos,num,r);

   

}

Comments