Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

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...

#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...

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

More C Interview Questions

why we are using semicolon at the end of printh statment

What is the maximum length of an identifier?

What is variable in c with example?

What's the total generic pointer type?

Find the largest number from the given 2 numbers without using any loops and the conditional operator.

write a programme to enter some number and find which number is maximum and which number is minimum from enterd numbers.

What does %c do in c?

what is the difference between %d and %*d in c languaga?

Explain the use of fflush() function?

#define f(x) main() { printf("\n%d",f(2+2)); }

Bit swapping

consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is

Categories
• C (4646)
• C++ (3462)
• VC++ (653)
• Delphi (566)
• Python Related (3238)
• PHP Related (7341)
• Scala (340)
• R Programming (396)
• Kotlin (184)
• Apache Groovy (39)
• Ruby (245)
• Go Programming Language (139)
• Objective-C (429)
• Programming Languages AllOther (736)