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...

How we can set and clear bit in a byte using macro function?

Answer Posted / c.p.senthil

#define SETBIT(num,bitpos) (num|(1<<bitpos))
#define CLRBIT(num,bitpos) (num&(~(1<<bitpos)))

int a = 0x03; // a = 00000011b = 0x03(3)
SETBIT(a, 3); // a = 00001011b [3rd bit set] = 0x0b(11)

int b = 0x25; // b = 00100101b = 0x25(37)
CLRBIT(b, 2); // b = 00100001b [2nd bit clear] = 0x21(33)

Is This Answer Correct ?    27 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

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

1275


p*=(++q)++*--p when p=q=1 while(q<=6)

1816


What is the difference between far and near in c?

1121


Why doesnt long int work?

1100


How can I recover the file name given an open stream?

1081


What is the use of pointers in C?

1134


Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

1148


What is use of pointer?

1172


How to find a missed value, if you want to store 100 values in a 99 sized array?

1463


Explain what is gets() function?

1120


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

1070


What is the method to save data in stack data structure type?

1147


Is c object oriented?

1016


Does c have an equivalent to pascals with statement?

1066


I have seen function declarations that look like this

1093