Toggle nth bit in a given integer - num

Answer Posted / vadivel t

#include<stdio.h>

int main()
{
int no, bit;
printf("ENTER THE NO AND BIT NO, TO TOGGLE: ");
scanf("%d %d", &
no, &bit);
if(no & (0x1 << bit-1))
{
no = no^(0x1 << bit - 1);
}
else
{
no = no | (0x1 << bit - 1);
}
printf("%d \n", no);

_getch();
}

Is This Answer Correct ?    3 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is getche() function?

604


What are Macros? What are its advantages and disadvantages?

644


Write a program to print fibonacci series using recursion?

584


What are the basic data types associated with c?

812


Differentiate call by value and call by reference?

564






What are the advantages of c preprocessor?

712


What is sizeof return in c?

612


How to declare a variable?

567


Array is an lvalue or not?

635


What is difference between function overloading and operator overloading?

652


Why isn't any of this standardized in c? Any real program has to do some of these things.

623


Explain the difference between call by value and call by reference in c language?

644


how to make a scientific calculater ?

1564


why wipro wase

1825


Why is c called c?

621