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
What is the difference between text and binary modes?
What does the characters “r” and “w” mean when writing programs that will make use of files?
What is auto keyword in c?
Write the Program to reverse a string using pointers.
What is void main () in c?
Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor
What are the application of void data type in c?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
What is the difference between text and binary i/o?
How will you divide two numbers in a MACRO?
What does struct node * mean?
What are the valid places to have keyword “break”?
What is the purpose of void in c?
Explain what is the heap?
How can I write a function analogous to scanf?