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...

Write a program using bitwise operators to invert even bits of
a given number.

Answer Posted / hari

#include<stdio.h>
int main()
{
int n,n2;
printf("enter the no. < 15 "); // here i am considering the case of 4 bits. (1111) binary = (15) decimal
scanf("%d",&n);
n2=n^10;

/*
10 = 1010 in binary form, to invert its even bits , we will
use bit wise XOR (^) operator
1010 has 1 at its even places, so it will invert the even bits of n.
if there is any further problem mail me at
buntyhariom@gmail.com
www.campusmaniac.com
*/
printf("\n%d",n2);

return 0;
}

Is This Answer Correct ?    10 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do variables need to be initialized?

1033


What is merge sort in c?

1043


How is a structure member accessed?

1125


Write a program to show the change in position of a cursor using c

1049


Explain the difference between strcpy() and memcpy() function?

992


Why does everyone say not to use scanf? What should I use instead?

1422


Do you know the use of 'auto' keyword?

1187


What is integer constants?

1070


What is a macro in c preprocessor?

1094


write a c program to calculate sum of digits till it reduces to a single digit using recursion

3303


Differentiate between full, complete & perfect binary trees.

1088


What is huge pointer in c?

1080


Is it better to use a macro or a function?

1154


What does 1f stand for?

1155


What is the best way to comment out a section of code that contains comments?

1335