Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Is int a keyword in c?

916


Mention four important string handling functions in c languages .

1055


What does emoji p mean?

1055


What is function definition in c?

1029


Can you please explain the difference between syntax vs logical error?

1140


Can you explain the four storage classes in C?

1081


is it possible to create your own header files?

1056


How do you construct an increment statement or decrement statement in C?

1184


Why we use conio h in c?

1165


What is the difference between #include and #include 'file' ?

1014


What is structure padding in c?

1071


Is fortran still used today?

1055


Write a program to print "hello world" without using a semicolon?

1020


What is the correct code to have following output in c using nested for loop?

1034


What are the different types of endless loops?

1033