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
Tell us two differences between new () and malloc ()?
p*=(++q)++*--p when p=q=1 while(q<=6)
What is the difference between far and near in c?
Why doesnt long int work?
How can I recover the file name given an open stream?
What is the use of pointers in C?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
What is use of pointer?
How to find a missed value, if you want to store 100 values in a 99 sized array?
Explain what is gets() function?
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
What is the method to save data in stack data structure type?
Is c object oriented?
Does c have an equivalent to pascals with statement?
I have seen function declarations that look like this