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
Is fortran still used in 2018?
What is pointer to pointer in c language?
c program to compute AREA under integral
What is an identifier?
What is the difference between text and binary i/o?
How can I read a binary data file properly?
What is the value of c?
Explain continue keyword in c
What are dangling pointers? How are dangling pointers different from memory leaks?
What is ## preprocessor operator in c?
What is the size of empty structure in c?
What is volatile keyword in c?
What are structure members?
How do I swap bytes?
What is c basic?