Write a program using bitwise operators to invert even bits of
a given number.
Answers were Sorted based on User's Feedback
#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 |
Answer / ayaskanta
Use Xor operation. Xor ing with 1 coverts a 0 to 1 and a 1
to zero...
| Is This Answer Correct ? | 3 Yes | 3 No |
write a progam to compare the string using switch case?
When should you not use a type cast?
What are preprocessor directives in c?
How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?
2 Answers Aricent, Manipal University,
how to use showbits function?
which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;
what is the other ways to find a logic to print whether a number is an even or odd wit out using % symbol??????? i know three different ways to print it. so i need any other different logic>>>>>
what is the use of #pragma pack, wer it is used?
Convert the following expression to postfix and prefix X $ Y Z - M + N + P / Q / (R + S)
How can I read a directory in a C program?
2 Answers Bright Outdoor, Wipro,
What is an arrays?
What is meant by type casting?