write a c program to change only the 3rd bit of the
particular number such that other bits are not affected..
if bitnum=10(say.. it can be any no..
Answer Posted / vadivel t
assume int holds 4bytes...
For ex:
#include <stdio.h>
int main()
{
int i = 16;
if(i & 0x04)
{
/*3rd bit is set to 1- so reset it to 0 - other bits will
not be disturbed*/
i = i & 0xFFFFFFFFB;
printf("IN IF \n");
}
else
{
/*3rd bit is set to 0- So set it to 1 - other bits will
not be disturbed*/
i = i | 0x00000004;
}
printf("%d", i);
_getch();
return 0;
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
Explain what is wrong with this statement? Myname = ?robin?;
Difference between strcpy() and memcpy() function?
What is the purpose of 'register' keyword in c language?
What is the use of void pointer and null pointer in c language?
What is the scope of an external variable in c?
What is the use of parallelize in spark?
Explain union. What are its advantages?
5 Write an Algorithm to find the maximum and minimum items in a set of ānā element.
What are the disadvantages of a shell structure?
Is c pass by value or reference?
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
Explain how can I convert a string to a number?
Differentiate between declaring a variable and defining a variable?
What is the use of bitwise operator?
What are shell structures used for?