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


Please Help Members By Posting Answers For Below Questions

What is the purpose of void in c?

615


pierrot's divisor program using c or c++ code

1724


What are the 5 elements of structure?

559


How do I determine whether a character is numeric, alphabetic, and so on?

618


How is a structure member accessed?

581






What are type modifiers in c?

615


what is the basis for selection of arrays or pointers as data structure in a program

3782


Once I have used freopen, how can I get the original stdout (or stdin) back?

620


Explain how many levels deep can include files be nested?

622


what are # pragma staments?

1621


Explain what are its uses in c programming?

590


What does the error 'Null Pointer Assignment' mean and what causes this error?

737


What is enumerated data type in c?

617


What is getche() function?

603


How do you determine a file’s attributes?

598