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 are register variables? What are the advantage of using register variables?
swap 2 numbers without using third variable?
What is the difference between procedural and declarative language?
what is the height of tree if leaf node is at level 3. please explain
what type of questions arrive in interview over c programming?
What is printf () in c?
how to introdu5ce my self in serco
What are the functions to open and close file in c language?
What is difference between structure and union with example?
write a program for the normal snake games find in most of the mobiles.
What is a static function in c?
How can you tell whether a program was compiled using c versus c++?
What are the types of c language?
What is modifier & how many types of modifiers available in c?
Explain argument and its types.