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 / om
int change_third_bit_only(int n, int bitToBeChanged)
{
int k1=1<<(bitToBeChanged-1) ;
//This is same as// int k1=pow(2, bitToBeChanged-1);
int k2=~k1;
if((n & k1) == 0)
//This means bitToBeChanged th bit in number n is 0
n=n | k1; // here changing it to 1
else //otherwise the bitToBeChanged th bit in number n is 1
n=n & k2; // here changing it to 0
return n;
}
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
write a c program to calculate sum of digits till it reduces to a single digit using recursion
There seem to be a few missing operators ..
What is the difference between far and near ?
What’s a signal? Explain what do I use signals for?
Can the “if” function be used in comparing strings?
When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.
Which node is more powerful and can handle local information processing or graphics processing?
What do you mean by recursion in c?
Why is C language being considered a middle level language?
Why is c called c?
How do c compilers work?
write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.
How can you read a directory in a C program?
How many types of sorting are there in c?
Can math operations be performed on a void pointer?