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

What is the advantage of c?

608


write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.

3334


What is the purpose of type declarations?

676


What does the error message "DGROUP exceeds 64K" mean?

725


What are register variables? What are the advantage of using register variables?

679






What is the difference between exit() and _exit() function in c?

579


An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above

704


What is getche() function?

604


What is a pointer in c?

678


Is c a great language, or what?

600


in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.

7388


How do shell structures work?

564


What are keywords c?

599


Which of these functions is safer to use : fgets(), gets()? Why?

632


Can you tell me how to check whether a linked list is circular?

765