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 typedef struct in c?
What is NULL pointer?
Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant
Explain about the functions strcat() and strcmp()?
What are identifiers and keywords in c?
What is the purpose of 'register' keyword in c language?
which is an algorithm for sorting in a growing Lexicographic order
Calculate 1*2*3*____*n using recursive function??
What are the types of i/o functions?
Why is C language being considered a middle level language?
cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration
In c programming language, how many parameters can be passed to a function ?
What is a stream water?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
Explain how do you determine the length of a string value that was stored in a variable?