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 c program to enter a string of paragraph and replacing a particular word which is repeated in the paragraph by another word?
2 Answers ME, Synfusion, Wipro,
What is the meaning of ?
What is the difference between malloc() and realloc()?
What is the best style for code layout in c?
prog for 1st five prime numbers in 2^x - 1
What is break in c?
Write a program to write a given string in maximum possibilities? i.e str[5]="reddy"; i.e we can write this string in 120 ways for that write a program
count the numbers between 100 and 300, that star with 2 and ends with 2
without using arithmatic operator convert an intger variable x into x+1
Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?
what is the coding of display the factorial of a number using array and function?
What is the deal on sprintf_s return value?