Write a program using bitwise operators to invert even bits of
a given number.
Answers were Sorted based on User's Feedback
#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 |
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 |
Explain high-order bytes.
Is c object oriented?
what is the difference between #include<stdio.h> and #include "stdio.h" ?
How to find a missed value, if you want to store 100 values in a 99 sized array?
What is difference between && and & in c?
How do I read the arrow keys? What about function keys?
Describe how arrays can be passed to a user defined function
Can anyone help me with this please? Need to print the below values.. Thanks 1 1 2 1 2 3 1 2 3 4
What is meant by 'bit masking'?
void main() { //char ch; unsigned char ch; clrscr(); for(ch =0;ch<= 127; ch++) printf(" %c= %d \t ", ch, ch); } output?
Write a C program to fill a rectangle using window scrolling
Write a C program to read the internal test marks of 25 students in a class and show the number of students who have scored more than 50% in the test. Make necessary assumptions.