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
Is c compiled or interpreted?
Why is c not oop?
What are pointers? What are different types of pointers?
Is c is a low level language?
What is #error and use of it?
What does the characters “r” and “w” mean when writing programs that will make use of files?
What is a keyword?
void main(int n) { if(n==0) return; main(--n); printf("%d ",n); getch(); } how it work and what will be its output...............it any one know ans plz reply
What is c language used for?
typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?
What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)?
How many bytes are occupied by near, far and huge pointers (dos)?
What should malloc(0) do?
Explain a file operation in C with an example.
What is an expression?