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 |
what is a NULL pointer?
What is array of structure in c programming?
what is compiler
What is a Genralised LInked List?? Please give a detailed explation of it..
how to make program without <> in library.
which is the best site or book for learning C...and i need the content for C..how to get the good programming skills....? can plz suggest me....
WHAT IS RTGS N MINIMUM AMT TO B TRANSFERD N WHAT R THE CHARGES ON MINIMUM AMT N IN WHICH BANK WE CAN DO IT?
Is c compiled or interpreted?
Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014 Npu university
how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....
How can I split up a string into whitespace-separated fields?
how to write a prog in c to convert decimal number into binary by using recursen function,