Question

For each of the following propositions, write in all comparisons that make it always true among...

For each of the following propositions, write in all comparisons that make it always true among the four possibilities:

< > == !=

If none are guaranteed to hold, please indicate that explicitly by marking it with an X. Assume the variables are declared with int x,y; and initialized to some unknown values. You may assume that int’s are 32 bits wide, char’s are 8 bits wide and that right shift is arithmetical on signed numbers and logical on unsigned numbers.

1. If x > y then y ? 0

2. If x < 0 then x+1 X 0

3. If x > 0 then x+1 ? 0

4. If (x >> 31) < 0 then x ? 0

5. If ((x > 31) < 0 then x & 1 ? 0

6. If x > y then (unsigned) x ? y

7. If ((unsigned char)x >> 1) < 64 then (char) x ? 0

Homework Answers

Answer #1

Answer :

Let x=5,y=3

1) if x>y the y?0

Ans: 5 > 3 then 3 >0 so

x > y then y > 0

Let x=-2

2) if x < 0 then x+1 X 0

Ans : -2 < 0 then -2+1 < 0

  x < 0 then x+1 < 0

Let x=2

3. If x > 0 then x+1 ? 0

Ans : 2>0 then 2+1 > 0

x > 0 then x+1 >0

Let x=-15

4. If (x >> 31) < 0 then x ? 0

Ans: (-15>>31)=-1

-1< 0 then x < 0

5. If ((x > 31) < 0 then x & 1 ? 0

Ans : Let x=32

((x > 31) < 0 then x & 1 == 0

6. If x > y then (unsigned) x ? y

Ans : x > y then (unsigned) x > y

7. If ((unsigned char)x >> 1) < 64 then (char) x ? 0

Ans : Let x= 34

x>>1 => 17 < 64 then x>0

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT