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

What is c system32 taskhostw exe?

0 Answers  


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

2 Answers   Cap Gemini, HCL,


Write a program that receives as input a number omaadel-n-print, four digits.

0 Answers  


Can stdout be forced to print somewhere other than the screen?

0 Answers  


Why main is not a keyword in c?

0 Answers  






a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none

0 Answers  


int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE) printf("1"); else printf("2"); }

2 Answers   Vector,


What is the difference between fread and fwrite function?

0 Answers  


what is a function prototype?

1 Answers  


Write a program for print infinite numbers

3 Answers   Wipro,


How to find the given no is odd or even without checking of any condition and loops. (Hint: Using array)

4 Answers  


What are the advantages of the functions?

0 Answers  


Categories