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

Place the #include statement must be written in the program?

576


hi, which software companys will take,if d candidate's % is jst 55%?

1669


What is s or c?

602


Difference between Function to pointer and pointer to function

636


What are nested functions in c?

568






A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(

1746


What is the acronym for ansi?

636


What is far pointer in c?

815


What is ambagious result in C? explain with an example.

2059


Why do we need volatile in c?

750


Explain how can I write functions that take a variable number of arguments?

619


Is register a keyword in c?

639


What is c language & why it is used?

587


What are header files in c programming?

660


What is the purpose of void in c?

624