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 an lvalue?
What is 2 d array in c?
What is the difference between malloc() and calloc() function in c language?
What is the difference between the = symbol and == symbol?
What are the types of type specifiers?
what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;
What is the difference between near, far and huge pointers?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
What is the modulus operator?
What is an expression?
Explain 'bit masking'?
How can I handle floating-point exceptions gracefully?
What is character set?
How do I copy files?
What does d mean?