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
Explain the difference between exit() and _exit() function?
Can you please explain the difference between strcpy() and memcpy() function?
Explain what is meant by high-order and low-order bytes?
What is meant by type casting?
how to write a c program to print list of fruits in alpabetical order?
How can you convert integers to binary or hexadecimal?
What is else if ladder?
How do you determine the length of a string value that was stored in a variable?
What is scanf () in c?
How main function is called in c?
What is the difference between declaring a variable by constant keyword and #define ing that variable?
Write a program in c to replace any vowel in a string with z?
What is the use of function overloading in C?
What does dm mean sexually?
What is self-referential structure in c programming?