Toggle nth bit in a given integer - num
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / banavathvishnu
#include<stdio.h>
#include<conio.h>
Togglebit(int k,int bit)
{
printf("after %d bit is toggled = %d",bit,(k^(1<<(bit-
1))));
return 1;
}
int main()
{
int i;
int bitno;
printf("enter the number \n");
scanf("%d",&i);
printf("enter the bit number to toggle \n");
scanf("%d",&bitno);
Togglebit(i,bitno);
getch();
return 1;
}
| Is This Answer Correct ? | 1 Yes | 4 No |
Which is better pointer or array?
What are the advantages of external class?
What is array in c with example?
main difference between c and c++ language
Explain data types & how many data types supported by c?
An application package has been provided to you without any documents for the following application. The application needs to be tested. How will you proceed?
What is New modifiers?
CAN WE DEFINE ANY FUNCTION WITHIN A FUNCTION.
What is a class?
simple program for virtual function?
What is #error and use of it?
How to add two numbers without using arithmetic operators?
18 Answers College School Exams Tests, e track, Infosys, Pan Parag, Sapient, TCS,