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

what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555

0 Answers   Wipro,


fn f(x) { if(x<=0) return; else f(x-1)+x; }

5 Answers   HCL,


What's a good way to check for "close enough" floating-point equality?

0 Answers   Celstream,


what are the files which are automatically opened when a c file is executed?

3 Answers  


What are the data types present in c?

0 Answers  






Describe for loop and write a c program to sum the series X + x2/2! + x3 /3! + …….. up to fifteen terms.

2 Answers  


What are the two types of functions in c?

0 Answers  


In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)

0 Answers   Wipro,


Why preprocessor should come before source code?

2 Answers  


triangle number finding program...

1 Answers   HCL,


How will you delete a node in DLL?

0 Answers   GrapeCity,


Write a program to find the biggest number of three numbers in c?

0 Answers  


Categories