Question: D) (10 Points) Consider running a C program that generates arbitrary values x and y, and convert them to unsigned values as follows: /* Create
D) (10 Points) Consider running a C program that generates arbitrary values x and y, and convert them to unsigned values as follows:
/* Create some arbitrary values */
int x = random();
int y = random();
/* Convert to unsigned */
unsigned ux = (unsigned) x;
unsigned uy = (unsigned) y;
Assume that:
- Values of type int are 32 bits.
- Values are represented in twos complement.
- Values are right shifted arithmetically.
- Values of type unsigned are also 32 bits
For each of the following C expressions, you are to indicate whether or not the expression always yields 1. If it always yields 1, explain why or describe the underlying mathematical principle. Otherwise, give an example of arguments that makes it yield 0.
1) (x < y) == (-x > -y)
2) ~x + ~y + 1 == ~(x + y)
3) (ux uy) == -(unsigned) (y x)
4) ((x >> 2) << 2) <= x
5) ((x + y) << 4) + y x == 17 * y + 15 * x
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
