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 |
How can I recover the file name given an open stream or file descriptor?
#include<stdio.h> int SumElement(int *,int); void main(void) { int x[10]; int i=10; for(;i;) { i--; *(x+i)=i; } printf("%d",SumElement(x,10)); } int SumElement(int array[],int size) { int i=0; float sum=0; for(;i<size;i++) sum+=array[i]; return sum; } output?
Is r written in c?
Write a program in c using only loops to print * * * * * *******
Write a program to use switch statement.
0 Answers Agilent, Integreon, ZS Associates,
main() { int a=5; printf(?%d,%d,%d\n?,a,a< <2,a>>2); } Answer: 5,20,1 please explain this code in detail
What is difference between constant pointer and constant variable?
2.main { int x,j,k; j=k=6;x=2; x=j*k; printf("%d", x);
What is the scope of static variable in c?
Explain what is the difference between functions getch() and getche()?
Input is "rama loves rajesh and rajesh Loves rama also and rajesh wear gloves and bloves" To print output is count the numbers of times repeted the word love without case sensitive.
Write a program to reverse a given number in c language?