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

Answer / 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

Write a program using bitwise operators to invert even bits of a given number...

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

Post New Answer

More C Interview Questions

What is the use of the restrict keyword?

1 Answers  


What is the difference between array_name and &array_name?

0 Answers  


Write a C Program to display the following menu: Menu 1. Display 2. Copy 3. Append 4. Exit Accept the choice (1-4) from the user, and perform the following tasks: Choice 1: Accept a file name from the user and display the file on screen Choice 2: Accept two file names, and copy first file to the second Choice 3: Accept two file names, and append second file to the first file Choice 4: Terminate the program

1 Answers   Accenture, Concor, DMU, Satyam, Syntel, Tora,


What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25

0 Answers  


Does * p ++ increment p or what it points to?

0 Answers  


34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?

0 Answers  


Write a program that will read the input of any number of digits n in a row of shafh showing the breakdown of the printing and printing figures by the recursive function.

0 Answers  


What do you mean by command line argument?

0 Answers   TCS,


What is a method in c?

0 Answers  


What language is lisp written in?

0 Answers  


How do I determine whether a character is numeric, alphabetic, and so on?

0 Answers  


In a byte, what is the maximum decimal number that you can accommodate?

0 Answers  


Categories