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

How to explain the final year project as a fresher please answer with sample project

922


What are control structures? What are the different types?

1056


How many loops are there in c?

1066


What is console in c language?

1064


What is pass by reference in c?

1158


Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

1042


What are the similarities between c and c++?

1024


about c language

1971


What are the different types of linkage exist in c?

989


Linked lists -- can you tell me how to check whether a linked list is circular?

1041


Why is c fast?

1019


Explain what is the benefit of using #define to declare a constant?

1122


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

1028


What is assignment operator?

1020


What is ponter?

1234