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 is a string?
What is identifier in c?
Who is the main contributor in designing the c language after dennis ritchie?
How can you draw circles in C?
Using which language Test cases are added in .ptu file of RTRT unit testing???
Explain what are the __date__ and __time__ preprocessor commands?
What is merge sort in c?
What is output redirection?
What is the purpose of main() function?
How can I read and write comma-delimited text?
What are the advantages of Macro over function?
What are inbuilt functions in c?
count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array
What language is c written?
What is the importance of c in your views?