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 me when would you use a pointer to a function?
What is the use of ?
What is the scope of global variable in c?
Why do we use stdio h and conio h?
Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.
Can we change the value of static variable in c?
Explain the use of fflush() function?
I have seen function declarations that look like this
How to define structures? ·
FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above
What are the different types of pointers used in c language?
Can a program have two main functions?
What are types of structure?
What is extern storage class in c?
What is a struct c#?