How we can set and clear bit in a byte using macro function?
Answers were Sorted based on User's Feedback
#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 |
Answer / sunitha
take i=5;
print its binary value
now for setting a bit
i=i>>5|1;
this will set 5th bit in binary value of 5
now for clearing a bit
i=i>>5 xor 1
this will clear 5th bit in binary value of 5
| Is This Answer Correct ? | 6 Yes | 3 No |
write a program to convert a expression in polish notation (postfix) to inline (normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix
What is sizeof int in c?
What is c language used for?
Explain the difference between structs and unions in c?
Tell us the use of fflush() function in c language?
how to swap 4 number without using temporary number?
What is sparse file?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
Is calloc better than malloc?
write a c code "if you give a any decimal number then print that number in english alphabet"? ex: i/p: 552 o/p: five hundred fifty two ...
#define f(x) main() { printf("\n%d",f(2+2)); }
write a progam to display the factors of a given number and disply how many prime numbers are there?