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

Explain what are preprocessor directives?

817


What is use of integral promotions in c?

869


Why does this code crash?

831


What is getch c?

1041


What is default value of global variable in c?

745


What is meant by int main ()?

939


What is c method?

736


How do you redirect a standard stream?

845


What is ctrl c called?

778


What is wild pointer in c with example?

773


What is header file definition?

808


Which one would you prefer - a macro or a function?

828


What is function definition in c?

778


Is c pass by value or reference?

799


What is difference between structure and union?

850