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
What does the error message "DGROUP exceeds 64K" mean?
What is wrong with this declaration?
What is a ternary operator in c?
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
What is the difference between functions abs() and fabs()?
What is an example of structure?
What language is c written?
Should I learn data structures in c or python?
how to execute a program using if else condition and the output should enter number and the number is odd only...
What are the functions to open and close the file in c language?
what type of questions arrive in interview over c programming?
What are the different types of linkage exist in c?
What is 2 d array in c?
What is a buffer in c?
What are the uses of null pointers?