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
Is a house a mass structure?
what is stack , heap ,code segment,and data segment
What is use of integral promotions in c?
can anyone suggest some site name..where i can get some good data structure puzzles???
about c language
What is else if ladder?
What is the basic structure of c?
What is difference between %d and %i in c?
c program to compute AREA under integral
How to define structures? ·
Why is #define used?
How does normalization of huge pointer works?
What is a void pointer? When is a void pointer used?
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321