write a c program to check weather a particluar bit is set
or not?

Answer Posted / kishora v

#include<stdio.h>
#include<conio.h>
main()
{
int n,p,r;
printf("entr the number\n");
scanf("%d",&n);
printf("enter the pos\n");
scanf("%d",&p);
r=(n&(1<<(p-1)));
if(r)
printf("bit is set");
else
printf("bit is not set");
getch();
}


if the question is check the bit if the bit is not set then
set that bit then we use the following code


#include<stdio.h>
#include<conio.h>
main()
{
int p,r;
static int n;
printf("entr the number\n");
scanf("%d",&n);
printf("enter the pos\n");
scanf("%d",&p);
r=(n&(1<<(p-1)));
if(r)
printf("bit is set");
else
{
printf("bit is not set");
n=n|(1<<p-1);
printf("number %d",n);
}
getch();
}

Is This Answer Correct ?    6 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is c called "mother" language?

849


If fflush wont work, what can I use to flush input?

602


Which driver is a pure java driver

983


write a program fibonacci series and palindrome program in c

627


Is calloc better than malloc?

565






Why shouldn’t I start variable names with underscores?

621


Explain about C function prototype?

597


write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.

14943


What is the process to create increment and decrement stamen in c?

581


What is the difference between text and binary modes?

637


What are derived data types in c?

602


int i=10; printf("%d %d %d", i, i=20, i);

1000


Can two or more operators such as and be combined in a single line of program code?

799


What is #include stdio h?

673


Explain the difference between the local variable and global variable in c?

591