Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are register variables? What are the advantage of using register variables?

1128


swap 2 numbers without using third variable?

1083


What is the difference between procedural and declarative language?

1094


what is the height of tree if leaf node is at level 3. please explain

2088


what type of questions arrive in interview over c programming?

1982


What is printf () in c?

1013


how to introdu5ce my self in serco

1938


What are the functions to open and close file in c language?

1131


What is difference between structure and union with example?

989


write a program for the normal snake games find in most of the mobiles.

2215


What is a static function in c?

1105


How can you tell whether a program was compiled using c versus c++?

1044


What are the types of c language?

976


What is modifier & how many types of modifiers available in c?

983


Explain argument and its types.

993