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
What do you understand by main document and data source
Oksana_A [137]

Answer:

The data source is a document, spreadsheet or database that contains personalized information such as names, addresses, and phone numbers. The Main Document can be a Form Letter, Labels, Email, or Directory.

<h2>Please mark me as brainliest</h2>

6 0
3 years ago
What is a function in Microsoft Excel?
uranmaximum [27]

Answer:

Tool for creating charts.

Explanation:

MS excel is clearly used for designing charts and spreadsheet in our daily life.

4 0
3 years ago
Write a program that converts temperatures in the Celsius scale to temperatures in the Fahrenheit scale. Your program should ask
Aleks [24]

Answer:

#include <iostream>

using namespace std;

int main()

{

   float celsius;

  cout<<"Enter the temperature in Celsius: ";

  cin>>celsius;

 

  float Fahrenheit  = 1.8 * celsius + 32;

  cout<<"The temperature in Fahrenheit  is: "<<Fahrenheit<<endl;

}

Explanation:

first include the library iostream in the c++ programming.

Then, create the main function and declare the variable celsius.

cout is used to print the message on the screen.

cin is used to store the user enter value in the variable.

then, apply the formula for calculating the temperature in Fahrenheit

and store the result in the variable.

Finally, print the result.

6 0
4 years ago
Younger people today are often called __________ because they have never known life without the Internet and cell phones.
iVinArrow [24]

Answer:

Digital Native

Explanation:

Digital natives are comfortable in the digital age, because they grew up using technology,  Digital natives are the opposite of digital immigrants, they have been interacting with technology from childhood.Digital natives see everyone on the equal level and are not dividing the world into hierarchies, they view the world horizontally. They cross boundaries and embrace the benefits of sharing with each other. Those values exist because of what they are driven by. Because of interacting with technology, digital natives think and process information fundamentally differently.

3 0
3 years ago
How to get fast frontend development online job as a beginner?​
mezya [45]

Answer:

hmmm well what is your magager?? every job will ask you what you can do.

3 0
3 years ago
Other questions:
  • Mary needs to choose the _____ menu in order to place the text in a desirable fashion around the image
    12·2 answers
  • Alto Innovations creates custom software for organizations. The company's managers want to build a high-performance culture in t
    11·1 answer
  • Which html attributes are required in the image () element - check as many as apply
    9·1 answer
  • A "start transaction" is set to be the system's first screen displayed once you log in to GCSS-Army. Setting up a start transact
    14·1 answer
  • We can include following item(s) during configuration itemidentification:
    10·1 answer
  • Please check my answer! (Java)
    6·1 answer
  • Jack started a job as a consultant with an IT firm he will be interacting with various customers and employees from different pa
    13·1 answer
  • Write a program that reads a list of integers into a vector, and outputs the two smallest integers in the list, in ascending ord
    5·1 answer
  • What is the main difference between a peripheral device and other types of devices? Choose the best answer.
    12·1 answer
  • Logistic Regression is a type of __________ problem.
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!