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 / gokulnaathan

#include <stdio.h>
int main()
{
unsigned int data = 0x000000f0;
int bitpos = 4;
int bitvalue = 1;
unsigned int bit = data;
bit = (bit>>bitpos)&0x00000001;
int invbitvalue = 0x00000001&(~bitvalue);
printf("%x\n",bit);

if(bitvalue ==0)
{
if(bit==0)
printf("%x\n",data);
else
{
data = (data^(invbitvalue<<bitpos));
printf("%x\n",data);
}
}
else
{
if(bit==1)
printf("elseif %x\n",data);
else
{
data = (data|(bitvalue<<bitpos));
printf("else %x\n",data);
}
}

}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell us two differences between new () and malloc ()?

1180


What is a loop?

1032


How can I open a file so that other programs can update it at the same time?

1179


What is sizeof int in c?

1054


Stimulate calculator using Switch-case-default statement for two numbers

2984


What does p mean in physics?

1034


Describe the steps to insert data into a singly linked list.

1068


What are external variables in c?

1098


In C programming, how do you insert quote characters (‘ and “) into the output screen?

1528


How can you convert integers to binary or hexadecimal?

1022


can any one provide me the notes of data structure for ignou cs-62 paper

2171


How do you override a defined macro?

1262


What is wild pointer in c?

1068


Explain the properties of union. What is the size of a union variable

1185


Is javascript based on c?

1061