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 are the disadvantages of a shell structure?

0 Answers  


Difference between malloc() and calloc() function?

0 Answers  


What is the difference between single charater constant and string constant?

0 Answers  


how the compiler treats any volatile variable?Explain with example.

1 Answers   Tata Elxsi,


What does sizeof function do?

0 Answers  






Why enum is used in c?

0 Answers  


how to find out the reverse number of a digit if it is input through the keyboard?

6 Answers  


write a c code "if you give a any decimal number then print that number in english alphabet"? ex: i/p: 552 o/p: five hundred fifty two ...

1 Answers   Philips,


What is structure and union in c?

0 Answers  


How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?

0 Answers  


What is scope and lifetime of a variable in c?

0 Answers  


Difference between C and Embedded C?

1 Answers  


Categories