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

  1. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!