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
Why is c called "mother" language?
If fflush wont work, what can I use to flush input?
Which driver is a pure java driver
write a program fibonacci series and palindrome program in c
Is calloc better than malloc?
Why shouldn’t I start variable names with underscores?
Explain about C function prototype?
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.
What is the process to create increment and decrement stamen in c?
What is the difference between text and binary modes?
What are derived data types in c?
int i=10; printf("%d %d %d", i, i=20, i);
Can two or more operators such as and be combined in a single line of program code?
What is #include stdio h?
Explain the difference between the local variable and global variable in c?