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
Tell us two differences between new () and malloc ()?
What is a loop?
How can I open a file so that other programs can update it at the same time?
What is sizeof int in c?
Stimulate calculator using Switch-case-default statement for two numbers
What does p mean in physics?
Describe the steps to insert data into a singly linked list.
What are external variables in c?
In C programming, how do you insert quote characters (‘ and “) into the output screen?
How can you convert integers to binary or hexadecimal?
can any one provide me the notes of data structure for ignou cs-62 paper
How do you override a defined macro?
What is wild pointer in c?
Explain the properties of union. What is the size of a union variable
Is javascript based on c?