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 / kishore batta
#include<stdio.h>
int main()
{
int number=0,set_bit=0,result=0;
printf("Enter the number:");
scanf("%x",&number);
printf("which bit to be set?:");
scanf("%x",&set_bit);
result=number|(0x1<<(set_bit-1));
printf("After setting the bit, the result is:%x
",result);
return 0;
}
OUTPUT:
Enter the number:1
which bit to be set?:4
After setting the bit, the result is:9
Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
What is the purpose of void in c?
pierrot's divisor program using c or c++ code
What are the 5 elements of structure?
How do I determine whether a character is numeric, alphabetic, and so on?
How is a structure member accessed?
What are type modifiers in c?
what is the basis for selection of arrays or pointers as data structure in a program
Once I have used freopen, how can I get the original stdout (or stdin) back?
Explain how many levels deep can include files be nested?
what are # pragma staments?
Explain what are its uses in c programming?
What does the error 'Null Pointer Assignment' mean and what causes this error?
What is enumerated data type in c?
What is getche() function?
How do you determine a file’s attributes?