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
How many types of operators are there in c?
Explain that why C is procedural?
What are the different file extensions involved when programming in C?
Write a program of prime number using recursion.
What is a function in c?
HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????
What are the different types of C instructions?
What are two dimensional arrays alternatively called as?
#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }
What is signed and unsigned?
What are near, far and huge pointers?
What does int main () mean?
What are enumerated types?
When c language was developed?
What does 2n 4c mean?