write a c program to check weather a particluar bit is set
or not?
Answers were Sorted based on User's Feedback
#include<stdio.h>
#include<conio.h>
int main()
{
int number;
int position;
int result;
printf("Enter the Number\n");
scanf("%d",&number);
printf("Enter the Position\n");
scanf("%d",&position);
result = (number >>(position-1));
if(result & 1)
printf("Bit is Set");
else
printf("Bit is Not Set");
}
| Is This Answer Correct ? | 33 Yes | 12 No |
Answer / valli
#include<stdio.h>
main()
{
int n,p;
printf("enter number");
scanf("%d",&n);
printf("enter the position");
scanf("%d",&p);
if(n&(1<<p))
printf("the bit is set");
else
printf("the bit is clear");
}
| Is This Answer Correct ? | 12 Yes | 3 No |
Answer / 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 |
Answer / vignesh1988i
#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,o,p;
printf("enter the number :");
scanf("%d",&m);
printf("enter the bit position for checking it is set or reset :");
scanf("%d",&n);
o=m;
p=o>>(n-1);
p=p&1;
if(p==1)
printf("the bit is set");
else
printf("the bit is reset");
getch();
}
thank u
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / abdur rab
#include <stdio.h>
int main ()
{
int variable = 6;
int position = 3;
char array [2][10] = {"NOT SET", "SET"};
// check the wheather the second bit is set
printf ( "\n The bit is %s",
array [ ( variable & ( 1 << (
position - 1 ) ) ) / position ] );
return ( 0 );
}
| Is This Answer Correct ? | 2 Yes | 3 No |
differentiate between const char *a; char *const a; and char const *a;
2 Answers College School Exams Tests, HCL, TCS,
Explain high-order bytes.
How can you determine the maximum value that a numeric variable can hold?
Write a main() program that calls this function at least 10 times. Try implementing this function in two different ways. First, use an external variable to store the count. Second, use a local variable. Which is more appropriate?
hi send me sample aptitude papers of cts?
Is c call by value?
program to find out date after adding 31 days to a date in the month of febraury also consider the leap year
What is else if ladder?
Why is c called c?
wat are the two methods for swapping two numbers without using temp variable??
What does c value mean?
how to go with this?