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
How arrays can be passed to a user defined function
What is a stream?
Why we write conio h in c?
What is chain pointer in c?
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
What is the value of c?
What is the use of pragma in embedded c?
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
In C, What is the #line used for?
provide an example of the Group by clause, when would you use this clause
Why does everyone say not to use scanf? What should I use instead?
How can I automatically locate a programs configuration files in the same directory as the executable?
What is file in c language?
What is array of structure in c programming?
What is an identifier?