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 / gokulnaathan
#include <stdio.h>
int main()
{
unsigned int data = 0x000000f0;
int bitpos = 4;
int bitvalue = 1;
unsigned int bit = data;
bit = (bit>>bitpos)&0x00000001;
int invbitvalue = 0x00000001&(~bitvalue);
printf("%x\n",bit);
if(bitvalue ==0)
{
if(bit==0)
printf("%x\n",data);
else
{
data = (data^(invbitvalue<<bitpos));
printf("%x\n",data);
}
}
else
{
if(bit==1)
printf("elseif %x\n",data);
else
{
data = (data|(bitvalue<<bitpos));
printf("else %x\n",data);
}
}
}
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What does 3 mean in texting?
What is the main difference between calloc () and malloc ()?
What is a volatile keyword in c?
What is the difference between printf and scanf )?
how to write a c program to print list of fruits in alpabetical order?
How do I swap bytes?
Explain the difference between structs and unions in c?
What are predefined functions in c?
What is difference between array and pointer in c?
What is indirection? How many levels of pointers can you have?
What does the message "automatic aggregate intialization is an ansi feature" mean?
How are portions of a program disabled in demo versions?
Explain how can you determine the size of an allocated portion of memory?
What are the advantages of using macro in c language?
What is c++ used for today?