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]
3 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]3 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
According to the ethical computer use policy, users should be __________ of the rules and, by agreeing to use the system on that
AURORKA [14]

Answer:

informed; consent

Explanation:

According to the ethical computer use policy, users should be informed of the rules and, by agreeing to use the system on that basis, consent to abide by the rules.

6 0
2 years ago
Why should you delete files from your computer? (multiple answers can be chosen)
Morgarella [4.7K]
<span>to increase the computer's efficiency

The more files it holds, the more "jobs" it has to run, which means that you're computer would be using the same amount of energy running all of them as to less of them. When you close (or delete) some files, it allows the computer to concentrate on only running a smaller amount of files as oppose to a large amount

hope this helps</span>
5 0
3 years ago
Read 2 more answers
Which of the following are typically an example of primary resources?
TiliK225 [7]
I believe the answer is B. Biographies and histories. (Otherwise its D)
5 0
3 years ago
Which shot is not the best for a widescreen image
sasho [114]
Closeup? I think I’m pretty sure but I don’t really know though
7 0
3 years ago
Read 2 more answers
Ross has to create a presentation for his class but can't decide on a topic. What should he do?
mylen [45]
Resheach thngs that instrest him and that fit the guidlines
6 0
3 years ago
Read 2 more answers
Other questions:
  • Let's say you're creating a search stream in your hootsuite dashboard, to find mentions of the phrase vacation holiday getaway.
    15·1 answer
  • This is not an appropriate business use for a wiki. editing corporate documents getting customer feedback project management pub
    11·1 answer
  • Does anybody know if that apple watch is actually worth what it costs?
    9·2 answers
  • What are some good electronics that I can buy on Amazon?
    14·1 answer
  • who will follow me on tiktok and like all my videos? if you do ill give branlist and give u a shoutout and you can enter my big
    15·1 answer
  • The first idea for a communications network was called
    14·2 answers
  • NAT is able to stop ________. Group of answer choices a) scanning probes sniffers from learning anything about the internal IP a
    8·2 answers
  • Speed(?)
    5·1 answer
  • Larry does not want to save his internet browsing details on his computer. What files should Larry delete to clear his informati
    13·2 answers
  • What does the following Boolean operators do?<br>AND function<br>OR function<br>NOT function​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!