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
Differentiate between declaring a variable and defining a variable?
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
write a programe to accept any two number and check the following condition using goto state ment.if a>b,print a & find whether it is even or odd and then print.and a
What does typeof return in c?
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
What is pointers in c?
largest Of three Number using without if condition?
What is array of structure in c programming?
How reliable are floating-point comparisons?
What is #line used for?
What library is sizeof in c?
Are pointers integer?
difference between native and cross compilers
Is c still used?
Write a code to generate a series where the next element is the sum of last k terms.