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


Please Help Members By Posting Answers For Below Questions

How can I recover the file name given an open stream?

559


Why should I use standard library functions instead of writing my own?

687


shorting algorithmS

1811


c language interview questions & answer

1468


What are the differences between new and malloc in C?

618






What are the characteristics of arrays in c?

622


Differentiate between static and dynamic modeling.

630


Can you add pointers together? Why would you?

660


When is a “switch” statement preferable over an “if” statement?

657


What would be an example of a structure analogous to structure c?

587


Is python a c language?

561


Explain 'far' and 'near' pointers in c.

714


A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(

1752


What does 3 periods mean in texting?

606


What is difference between union and structure in c?

587