▾ Part A - The effect of an arithmetic shift on signed numbers Let's look at see what happens to signed numbers during a shift operation. As with most problems with number representations, errors can be intermittent. Sometimes the code will work as expected, and other times it will behave in a manner that seems to be totally arbitrary. Consider the following code fragment that makes use of the fact that shifting a value left by one place multiplies the number by 2. By passing in the number to be multiplied and the power of 2 to multiply it by (for example 4 = 22) the correct answer should be passed back from the function after the results are printed for the user to examine signed int mult_2_to_n (signed int num, int n) ( signed int result; result = num << n; printf("%d multiplied by 2^d = $d\n", num, n, result); return result; } Using a signed number as the manipulated integer may cause an error in some cases. Several approaches may be used to fix the problem. Which solutions below are valid? (Assume that the return type will be modified as needed, and that there will be no unintended bits lost due to left-shiting) Select all answers that apply. There will be at least one correct answer. ▸ View Available Hint(s) saving the signed bit and restoring it at the end of the shift Ochanging the signed int to a representation that can be preserved □ shifting num to the right in the return statement Oshifting the signed bit to the left one more time □ checking that the shift is small enough not to interfere with the signed bit Submit Request Answer Activate Windows Go to Settings to activate Windows.
▾ Part A - The effect of an arithmetic shift on signed numbers Let's look at see what happens to signed numbers during a shift operation. As with most problems with number representations, errors can be intermittent. Sometimes the code will work as expected, and other times it will behave in a manner that seems to be totally arbitrary. Consider the following code fragment that makes use of the fact that shifting a value left by one place multiplies the number by 2. By passing in the number to be multiplied and the power of 2 to multiply it by (for example 4 = 22) the correct answer should be passed back from the function after the results are printed for the user to examine signed int mult_2_to_n (signed int num, int n) ( signed int result; result = num << n; printf("%d multiplied by 2^d = $d\n", num, n, result); return result; } Using a signed number as the manipulated integer may cause an error in some cases. Several approaches may be used to fix the problem. Which solutions below are valid? (Assume that the return type will be modified as needed, and that there will be no unintended bits lost due to left-shiting) Select all answers that apply. There will be at least one correct answer. ▸ View Available Hint(s) saving the signed bit and restoring it at the end of the shift Ochanging the signed int to a representation that can be preserved □ shifting num to the right in the return statement Oshifting the signed bit to the left one more time □ checking that the shift is small enough not to interfere with the signed bit Submit Request Answer Activate Windows Go to Settings to activate Windows.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question

Transcribed Image Text:▼
Part A - The effect of an arithmetic shift on signed numbers
Let's look at see what happens to signed numbers during a shift operation.
As with most problems with number representations, errors can be intermittent. Sometimes the code will work as expected, and other times it will behave in a manner that seems to be totally arbitrary. Consider the following code fragment that makes use of the fact that shifting a
value left by one place multiplies the number by 2. By passing in the number to be multiplied and the power of 2 to multiply it by (for example 4 = 22) the correct answer should be passed back from the function after the results are printed for the user to examine.
signed int mult_2_to_n (signed int num, int n)
{
signed int result;
result = num << n;
printf("%d multiplied by 2^%d %d\n", num, n, result);
return result;
}
Using a signed number as the manipulated integer may cause an error in some cases. Several approaches may be used to fix the problem. Which solutions below are valid? (Assume that the return type will be modified as needed, and that there will be no unintended bits lost
due to left-shiting).
Select all answers that apply. There will be at least one correct answer.
► View Available Hint(s)
saving the signed bit and restoring it at the end of the shift
changing the signed int to a representation that can be preserved
Oshifting num to the right in the return statement
Oshifting the signed bit to the left one more time
Ochecking that the shift is small enough not to interfere with the signed bit
Submit
Request Answer
Activate Windows
Go to Settings to activate Windows.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education