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 |
Differentiate between full, complete & perfect binary trees.
Does * p ++ increment p or what it points to?
void main() { for(; 0 ;) ... { printf("hello"); ... } getch(); }
count the numbers between 100 and 300, that star with 2 and ends with 2
what is the output of the following code? main() { int I; I=0x10+010+10; printf("x=%x",I); } give detailed reason
What is typedef?
How can I find out the size of a file, prior to reading it in?
Function to find the given number is a power of 2 or not?
What does char * * argv mean in c?
Find greatest number out of 10 number without using loop.
int x=5; printf("%d%d%d",x,x<<2,x>>2);
write a program without using main function?