Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / ayaskanta

Use Xor operation. Xor ing with 1 coverts a 0 to 1 and a 1
to zero...

Is This Answer Correct ?    3 Yes 3 No

Post New Answer

More C Interview Questions

why we are using semicolon at the end of printh statment

2 Answers   HCL,


What is the maximum length of an identifier?

0 Answers  


What is variable in c with example?

0 Answers  


What's the total generic pointer type?

0 Answers  


Find the largest number from the given 2 numbers without using any loops and the conditional operator.

2 Answers  






write a programme to enter some number and find which number is maximum and which number is minimum from enterd numbers.

3 Answers  


What does %c do in c?

0 Answers  


what is the difference between %d and %*d in c languaga?

7 Answers   TCS,


Explain the use of fflush() function?

0 Answers  


#define f(x) main() { printf("\n%d",f(2+2)); }

5 Answers  


Bit swapping

2 Answers  


consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is

4 Answers   TCS,






Categories