Question
I need help with these 2 question using UNIX The & operator can be used to quickly check if a number is odd or even.
I need help with these 2 question using UNIX
- The & operator can be used to quickly check if a number is odd or even. The value of expression (x & 1) would be non-zero only if x is odd, otherwise the value would be zero.
#include int main() { //User enters an integer number // if x is even, print even, otherwise print odd using & operator return 0; } |
Complete the above program and test it with 17, 19, 22, 100.
Your output :
3.
Suppose two integer values a and b Perform, x = a ^ b Now x ^ b will evaluate to a and x ^ a will evaluate to b.
The following program is to swap two numbers using xor operator.
/**
* C program to swap two numbers using bitwise operator
*/
#include
int main()
{
int num1, num2;
/* Input two numbers from user */
printf("Enter any two numbers: ");
scanf("%d%d", &num1, &num2);
printf("Original value of num1 = %d ", num1);
printf("Original value of num2 = %d ", num2);
/* Swap two numbers */
//Fill out the codes using xor operator
printf("Num1 after swapping = %d ", num1);
printf("Num2 after swapping = %d ", num2);
return 0;
}
Output with test case: 66, 22
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started