how to find a 5th bit is set in c program

Answers were Sorted based on User's Feedback



how to find a 5th bit is set in c program..

Answer / valli

main()
{
int n;
printf("enter n:");
scanf("%d",&n);
if(n&(1<<5);
printf("5th bit in %d is set",n);
}

Is This Answer Correct ?    20 Yes 2 No

how to find a 5th bit is set in c program..

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 ?    18 Yes 7 No

how to find a 5th bit is set in c program..

Answer / rajkumar

#include<stdio.h>
void main()
{
int a;
a=a>>4;
if(a%2==1)
printf("the bit is set");
else
printf("the bit is not set");
}

Is This Answer Correct ?    9 Yes 3 No

how to find a 5th bit is set in c program..

Answer / sumit kumar

Take the input 5 from keyword :-
#include<stdio.h>
main()
{
int num,pos;
printf("enter the no.:");
scanf("%d",&num);
printf("enter the position:");
scanf("%d",&pos);
if(num & (1<<pos))
{
printf("pos is set");
}
else
{
printf("pos is not set");
}
}

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More C Interview Questions

int *a[5] refers to

12 Answers   TCS,


How to Throw some light on the splay trees?

0 Answers  


There are 8 billiard balls, and one of them is slightly heavier, but the only way to tell was by putting it on a weighing scale against another. What's the fewest number of times you'd have to use the scale to find the heavier ball?

5 Answers   Microsoft, TCS,


what is the most appropriate way to write a multi-statement macro?

1 Answers  


What's the difference between constant char *p and char * constant p?

0 Answers   Celstream,


What does extern mean in a function declaration?

4 Answers  


to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?

0 Answers  


Write a program to reverse a string.

0 Answers   Global Logic, iNautix, TCS, Wipro,


What is the use of putchar function?

0 Answers  


How do you define a function?

0 Answers  


write a C code to reverse a string using a recursive function, without swapping or using an extra memory.

9 Answers   Motorola, TCS, Wipro,


Write a Program to accept different goods with the number, price and date of purchase and display them

0 Answers   HDFC,


Categories