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
How to explain the final year project as a fresher please answer with sample project
What are control structures? What are the different types?
How many loops are there in c?
What is console in c language?
What is pass by reference in c?
Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]
What are the similarities between c and c++?
about c language
What are the different types of linkage exist in c?
Linked lists -- can you tell me how to check whether a linked list is circular?
Why is c fast?
Explain what is the benefit of using #define to declare a constant?
Synonymous with pointer array a) character array b) ragged array c) multiple array d) none
What is assignment operator?
What is ponter?