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
What is a program flowchart and explain how does it help in writing a program?
Explain Basic concepts of C language?
How to Throw some light on the splay trees?
Why we use break in c?
What math functions are available for integers? For floating point?
What does sizeof int return?
Apart from dennis ritchie who the other person who contributed in design of c language.
What is the g value paradox?
What is volatile keyword in c?
What does c mean?
What is the difference between void main and main in c?
write a program to rearrange the array such way that all even elements should come first and next come odd
How can you increase the size of a statically allocated array?
Ow can I insert or delete a line (or record) in the middle of a file?
What is sizeof return in c?