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
Write a program to check palindrome number in c programming?
program to find out date after adding 31 days to a date in the month of febraury also consider the leap year
Badboy is defined who has ALL the following properties: Does not have a girlfriend and is not married. He is not more than 23 years old. The middle name should be "Singh" The last name should have more than 4 characters. The character 'a' should appear in the last name at least two times. The name of one of his brothers should be "Ram" Write a method: boolean isBadBoy(boolean hasGirlFriend , boolean isMarried, int age , String middleName , String lastName , String[] brotherName); isHaveGirlFriend is true if the person has a girlfriend isMarried is true if the person is married age is the age of the person middleName is the middle name of the person lastName is the last name of the person brotherName is the array of the names of his brothers
What are the advantages of using linked list for tree construction?
What is .obj file in c?
Are local variables initialized to zero by default in c?
Explain logical errors? Compare with syntax errors.
What are 3 types of structures?
What is the description for syntax errors?
to find the closest pair
What is the use of clrscr?
What is the difference between declaring a variable by constant keyword and #define ing that variable?
Does * p ++ increment p or what it points to?
Explain null pointer.
Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same.