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
Place the #include statement must be written in the program?
hi, which software companys will take,if d candidate's % is jst 55%?
What is s or c?
Difference between Function to pointer and pointer to function
What are nested functions in c?
A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(
What is the acronym for ansi?
What is far pointer in c?
What is ambagious result in C? explain with an example.
Why do we need volatile in c?
Explain how can I write functions that take a variable number of arguments?
Is register a keyword in c?
What is c language & why it is used?
What are header files in c programming?
What is the purpose of void in c?