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 |
what is the maximum limit of row and column of a matrix in c programming. in linux .
Write a c program to print the sizes and ranges of different data types in c?
Here is alphabets : abcdefgh 1) how to reverse. as hgfedcba 2) after reversal, how to group them in a pair hg fe dc ba.
What is the size of empty structure in c?
Is sizeof a keyword in c?
Write a C program that reads a series of strings and prints only those ending in "ed"
How to write a code for implementing my own printf() and scanf().... Please hep me in this... I need a guidance... Can you give an coding for c... Please also explain about the header files used other than #include<stdio.h>...
Is the following code legal? struct a { int x; struct a b; }
hi, which software companys will take,if d candidate's % is jst 55%?
What does the error 'Null Pointer Assignment' mean and what causes this error?
create an SINGLE LINKED LISTS and reverse the data in the lists completely
What is structure and union in c?