Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. Write a function with the following prototype: /* Determine whether arguments

ID: 3888258 • Letter: 5

Question

5. Write a function with the following prototype: /* Determine whether arguments can be subtracted without overflow/ int tsub_ok(int x, int y); This function should return 1 if the computation x - y does not overflow. 6. Convert the following numbers as indicated, using as few digits in the results as necessary. (a) (010101)2 to base 10 (b) (011100)2 to base 16 (c) (54.125)ho to binary (d) (122.3)4 to base 16 7. Show the results of adding the following pairs of five-bit two's complement numbers and indicate whether or not overflow occurs for each case. (a) 11110 + 11101; (b) 10111 + 10111; 8. Assuming a 64-bit machine and two's complement representation for integers, show the total number of bits used, and all the bit values, for the following variables: char c = 35; char d = ,G"; int x - -42;

Explanation / Answer

Please find my answer for Q5.

Please repost other questions in separate post.

Please let me know in case of any issue in Q5.

There can be overflow only if signs of two numbers are same, and sign of sum is opposite to the signs of numbers.

1) Calculate sum

2) If both numbers are positive and sum is negative then return -1

Else

If both numbers are negative and sum is positive then return -1

Else return 0

int tsub_ok(int x, int y) {

y = -y; // making y negative, so that we can calculate (x + (-y)) => x - y

int sum = x + y;

if(x >= 0 && y >= 0 && sum < 0)

return 0;

else if(x < 0 && y < 0 && sum > 0)

return 0;

else

return 1;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote