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
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
What is the purpose of macro in C language?
How can I pad a string to a known length?
int i=10; printf("%d %d %d", i, i=20, i);
What is || operator and how does it function in a program?
Explain can the sizeof operator be used to tell the size of an array passed to a function?
any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above
which is an algorithm for sorting in a growing Lexicographic order
What is bubble sort in c?
Is c++ based on c?
What are structures and unions? State differencves between them.
What is the difference between memcpy and memmove?
Why does notstrcat(string, "!");Work?
Why do we use return in c?
What is #line used for?