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 change only the 3rd bit of the
particular number such that other bits are not affected..
if bitnum=10(say.. it can be any no..

Answer Posted / om

int change_third_bit_only(int n, int bitToBeChanged)
{
int k1=1<<(bitToBeChanged-1) ;
//This is same as// int k1=pow(2, bitToBeChanged-1);
int k2=~k1;
if((n & k1) == 0)
//This means bitToBeChanged th bit in number n is 0
n=n | k1; // here changing it to 1
else //otherwise the bitToBeChanged th bit in number n is 1
n=n & k2; // here changing it to 0

return n;
}

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between exit() and _exit() function?

1175


Can you please explain the difference between strcpy() and memcpy() function?

1081


Explain what is meant by high-order and low-order bytes?

1053


What is meant by type casting?

1064


how to write a c program to print list of fruits in alpabetical order?

2306


How can you convert integers to binary or hexadecimal?

1040


What is else if ladder?

1030


How do you determine the length of a string value that was stored in a variable?

1128


What is scanf () in c?

1133


How main function is called in c?

1135


What is the difference between declaring a variable by constant keyword and #define ing that variable?

3384


Write a program in c to replace any vowel in a string with z?

1137


What is the use of function overloading in C?

1182


What does dm mean sexually?

1327


What is self-referential structure in c programming?

1227