write a c program to check weather a particluar bit is set
or not?

Answers were Sorted based on User's Feedback



write a c program to check weather a particluar bit is set or not?..

Answer / santhi perumal

#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

write a c program to check weather a particluar bit is set or not?..

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

write a c program to check weather a particluar bit is set or not?..

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

write a c program to check weather a particluar bit is set or not?..

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

write a c program to check weather a particluar bit is set or not?..

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

Post New Answer

More C Interview Questions

how to write a data 10 in address location 0x2000

3 Answers  


Convert the following expression to postfix and prefix X $ Y Z - M + N + P / Q / (R + S)

2 Answers  


What is variables in c?

0 Answers  


1) int main() { unsigned char a = 0; do { printf("%d=%c\n",a,a); a++; }while(a!=0); return 0; } can anyone please explain the explain the output

2 Answers  


What are the back slash character constants or escape sequence charactersavailable in c?

0 Answers  


write a program for 4 4 3 3 3 3 2 2 2 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 4 4

1 Answers  


i have a written test in tomorrow

1 Answers   NNN, Value Labs,


main() { int i=400,j=300; printf("%d..%d"); }

13 Answers   ME,


Is exit(status) truly equivalent to returning the same status from main?

0 Answers  


Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

0 Answers  


What is the use of the #include directive?

3 Answers  


how to set Nth bit of variable by using MACRO

3 Answers   HCL,


Categories