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
Do variables need to be initialized?
What is merge sort in c?
How is a structure member accessed?
Write a program to show the change in position of a cursor using c
Explain the difference between strcpy() and memcpy() function?
Why does everyone say not to use scanf? What should I use instead?
Do you know the use of 'auto' keyword?
What is integer constants?
What is a macro in c preprocessor?
write a c program to calculate sum of digits till it reduces to a single digit using recursion
Differentiate between full, complete & perfect binary trees.
What is huge pointer in c?
Is it better to use a macro or a function?
What does 1f stand for?
What is the best way to comment out a section of code that contains comments?