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
Can you write the algorithm for Queue?
How many keywords are there in c?
What is array of structure in c programming?
please explain every phase in the "SDLC" in the dotnet.
What are the types of data structures in c?
What is meant by preprocessor in c?
How to write a multi-statement macro?
What are reserved words?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.
#include
Explain bit masking in c?
Explain what are multidimensional arrays?
what are the facialities provided by you after the selection of the student.
Why is it that not all header files are declared in every C program?
Write a program to swap two numbers without using third variable in c?