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 |
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
fn f(x) { if(x<=0) return; else f(x-1)+x; }
What's a good way to check for "close enough" floating-point equality?
what are the files which are automatically opened when a c file is executed?
What are the data types present in c?
Describe for loop and write a c program to sum the series X + x2/2! + x3 /3! + …….. up to fifteen terms.
What are the two types of functions in c?
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)
Why preprocessor should come before source code?
triangle number finding program...
How will you delete a node in DLL?
Write a program to find the biggest number of three numbers in c?