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 difference between structure and union with example?
what are the different storage classes in c?
What is c language and why we use it?
Why is c called a structured programming language?
How to throw some light on the b tree?
Which type of language is c?
please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code
What is type qualifiers?
Is there a way to compare two structure variables?
write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays
Can a program have two main functions?
Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)
What is the condition that is applied with ?: Operator?
how is the examination pattern?
Can two or more operators such as and be combined in a single line of program code?