1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Diano4ka-milaya [45]
4 years ago
12

Write code for a function with the following prototype: /* Addition that saturates to TMin or TMax */ int saturating_add(int x,

int y); Instead of overflowing the way normal two's-complement addition does, saturating addition returns TMax when there would be positive overflow, and TMin when there would be negative overflow. Saturating arithmetic is commonly used in programs that perform digital signal processing. Your function should follow the bit-level integer coding rules (page 128).
Computers and Technology
1 answer:
Kazeer [188]4 years ago
7 0

Answer:

See explaination

Explanation:

program code.

/* PRE PROCESSOR DIRECTIVES */

#include<stdio.h>

/* PRE-DEFINED VALUES FOR TMAX AND TMIN */

#define TMax 2147483647

#define TMin (-TMax -1)

/* saturating_add(int,int) METHOD IS CALLED HERE */

int saturating_add(int firstNumber, int secondNumber)

{

/*

FOR BETTER UNDERSTANDING, LETS TAKE TEST CASE,

WHERE firstNumber = 5 AND secondNumber = 10

*/

int w = sizeof(firstNumber) << 3;

/*

sizeof(firstNumber) VALUE IS 4, SO USING BINARY LEFT SHIFT OPERATOR TO THREE PLACES,

WE HAVE NOW VALUE 32, ASSIGNED TO w

*/

/* ADDITION IS CALCULATED => 15 */

int addition = firstNumber + secondNumber;

/*

MASK INTEGER VARIABLE IS TAKEN

mask BIT IS LEFT SHIFTED TO 31 PLACES => 2^31 IS THE NEW VALUE

*/

int mask = 1 << (w - 1);

/* FIRST NUMBER MOST SIGNIFICANT BIT IS CALCULATED BY USING AND OPERATOR */

int msbFirstNumber = firstNumber & mask;

/* SECOND NUMBER MOST SIGNIFICANT BIT IS CALCULATED BY USING AND OPERATOR */

int msbSecondNumber = secondNumber & mask;

/* MOST SIGNIFICANT BIT OF ADDITION IS CALCULATED BY USING AND OPERATOR */

int msbAddition = addition & mask;

/* POSITIVE OVERFLOW IS DETERMINED */

int positiveOverflow = ~msbFirstNumber & ~msbSecondNumber & msbAddition;

/* NEGATIVE OVERFLOW IS DETERMINED */

int negativeOverflow = msbFirstNumber & msbSecondNumber & !msbAddition;

/* THE CORRESPONDING VALUE IS RETURNED AS PER THE SATURATING ADDITION RULES */

(positiveOverflow) && (addition = TMax);

(negativeOverflow) && (addition = TMin);

return addition;

}

/* MAIN FUNCTION STARTS HERE */

int main(){

/* TEST CASE */

int sum = saturating_add(5, 10);

/* DISPLAY THE RESULT OF TEST CASE */

printf("The Sum Is : %d\n\n",sum);

}

You might be interested in
How do I get rid of this little tool bar????
Serhud [2]

Answer:

settings>Accessibility>Touch>AssistiveTouch>Turn off

Explanation:

4 0
3 years ago
Please name the OOP term that allows children classes to have methods with the same names as methods in their parents.
RSB [31]

Answer:

Inheritance

Explanation:

3 0
3 years ago
Free up disk space by doing____?​
8090 [49]

Answer:

Deleting files and etc on your computer.

6 0
3 years ago
Read 2 more answers
A virus has attacked your hard drive. Instead of seeing the Windows Start screen when you start up Windows, the system freezes a
Yanka [14]

Answer:

Boot to safe mode

Explanation:

When a virus attacks boot system, that is to say, Windows program won´t load. The following steps should be considered taking into account what Windows Version is being used, Windows 7, 8 or 10:

1. Press  F8 (Windows 7) F4 (Windows 8, 10)

2. Enable Safe Mode

3. Run Safe Mode

4. Once in safe mode the user will have access to Windows and eventually document files can be extracted via pendrive.

5 0
3 years ago
Give two examples of html structure
butalik [34]

Answer:

semantic information that tells a browser how to display a page and mark up the content within a document

7 0
3 years ago
Other questions:
  • What benefit does internet have​
    11·1 answer
  • Which of the following is a rule of thumb for cell phones or smartphone etiquette ?
    12·1 answer
  • Can anyone find any words in here?
    14·2 answers
  • What command can be used to export an nps backup file named npsconfig.xml that can be used to restore nps configuration on anoth
    12·1 answer
  • True or false? Resistors regulate and limit electrical current. A. True B. False
    7·2 answers
  • Computer privacy typically occurs when which of the following is violated?
    6·1 answer
  • Please Help meeeeeeeeeee:
    11·2 answers
  • An algorithm is:
    14·1 answer
  • Saujani describes that women are highly underrepresented in STEM careersShe attributes this to women needing more confidence. Wh
    13·1 answer
  • Question 1 of 10
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!