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 / vadivel t

assume int holds 4bytes...

For ex:

#include <stdio.h>
int main()
{
int i = 16;
if(i & 0x04)
{
/*3rd bit is set to 1- so reset it to 0 - other bits will
not be disturbed*/
i = i & 0xFFFFFFFFB;
printf("IN IF \n");
}
else
{
/*3rd bit is set to 0- So set it to 1 - other bits will
not be disturbed*/
i = i | 0x00000004;
}
printf("%d", i);
_getch();
return 0;
}

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is wrong with this statement? Myname = ?robin?;

1641


Difference between strcpy() and memcpy() function?

1217


What is the purpose of 'register' keyword in c language?

1076


What is the use of void pointer and null pointer in c language?

1169


What is the scope of an external variable in c?

1097


What is the use of parallelize in spark?

1065


Explain union. What are its advantages?

1128


5 Write an Algorithm to find the maximum and minimum items in a set of ā€˜n’ element.

2161


What are the disadvantages of a shell structure?

1428


Is c pass by value or reference?

1112


find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2

2049


Explain how can I convert a string to a number?

1148


Differentiate between declaring a variable and defining a variable?

1091


What is the use of bitwise operator?

1175


What are shell structures used for?

1096