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

What are the 3 types of structures?

572


What is equivalent to ++i+++j?

643


Why string is used in c?

580


Explain 'bus error'?

561


What do you know about the use of bit field?

612






When was c language developed?

703


Is c high or low level?

582


What is sizeof return in c?

617


What is typedf?

670


Difference between constant pointer and pointer to a constant.

613


What does do in c?

610


What is storage class?

654


The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none

713


What do you mean by recursion in c?

626


How can I manipulate individual bits?

608