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


Please Help Members By Posting Answers For Below Questions

How arrays can be passed to a user defined function

565


What is a stream?

636


Why we write conio h in c?

549


What is chain pointer in c?

591


Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given

2499






What is the value of c?

560


What is the use of pragma in embedded c?

583


an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational

796


In C, What is the #line used for?

1033


provide an example of the Group by clause, when would you use this clause

1692


Why does everyone say not to use scanf? What should I use instead?

674


How can I automatically locate a programs configuration files in the same directory as the executable?

615


What is file in c language?

566


What is array of structure in c programming?

741


What is an identifier?

616