Toggle nth bit in a given integer - num

Answer Posted / sanyam jain

#include<stdio.h>
int main()
{
int a,b;
printf("Enter the number to be flipped\n");
scanf("%d",&a);
printf("Enter which bit to be flipped: ");
scanf("%d",&b);

a = a^(1<<(b-1));
printf("Resultan number is %d\n",a);
}

Is This Answer Correct ?    6 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Create a simple code fragment that will swap the values of two variables num1 and num2.

1039


which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above

1771


What is the difference between declaring a variable and defining a variable?

948


In which language linux is written?

921


i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....

1725


What are the benefits of organizational structure?

775


Explain what is a pragma?

792


What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }

2261


What is array within structure?

824


Explain how can I manipulate strings of multibyte characters?

982


What is the use of bitwise operator?

882


What does typedef struct mean?

848


Is javascript written in c?

787


What is difference between Structure and Unions?

875


What is modifier & how many types of modifiers available in c?

814