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
The impact of the destruction of train station on the budget of the minister of finance
zhuklara [117]

The impact of the destruction of train station on the budget of the minister of finance is said to be very huge.

<h3>How do railways destruction affect the economy?</h3>

When there is railroads destruction, a lot of money such as billions of dollars is been spent to repair the damages and this will be of a great concern to the minister of finance.

Most countries is run by Budget and when sudden things like this happen, the Minister have to look for other ways to source for funds and this will affect other parts or items on the budget of the Minister.

Learn more about  minister of finance from

brainly.com/question/470781

7 0
2 years ago
What is the Matlab command to create a vector of the even whole numbers between 29 and 73?
Nana76 [90]

Answer:

x = 29:73;

x_even = x(2:2:end);

Explanation:

In order to create a vector in Matlab you can use colon notation:

x = j:k

where <em>j</em> is 29 and <em>k</em> is 73 in your case:

x = 29:73

Then you can extract the even numbers by extracting the numbers with even index (2,4,6,etc.) of your vector:

x_even = x(2:2:end);

In the line of code above, we define <em>x_even</em> as all the elements of x with even index from index 2 till the end index of your vector, and an increment of 2 in the index: 2,4,6,etc.

If you want the odd numbers, just use the odd indices of your vector:

x_odd = x(1:2:end);

where <em>x_odd</em> contains all the elements of <em>x</em> with odd index from index 1 till the end index, and an increment of 2: 1,3,5,etc.

6 0
3 years ago
List and describe four services that comprise IT infrastructure, beyond physical devices and software applications.
masha68 [24]

The four services that comprise IT infrastructure are:

  • Telecommunications services.
  • Data management services .
  • Application software services.
  • Physical facilities management services.

<h3>What does these services do?</h3>

Telecommunications services is known to help in terms of giving data, voice, and video network.

Data management services helps to save , manage, and analyze all data. Application software services helps to give firms-wide range capabilities.

The Physical facilities management services helps to make and handle physical installations of technology.

Therefore, The four services that comprise IT infrastructure are:

  • Telecommunications services.
  • Data management services .
  • Application software services.
  • Physical facilities management services.

Learn more about  IT infrastructure from

brainly.com/question/869476

#SPJ1

6 0
2 years ago
What is the purpose of quick access toolbar?
Flauer [41]
Answer:

Toolbar grants direct (quick) access to a set of desired commands in a toolbar that is always visible no matter which ribbon tab is selected.

Explanation:


Given
8 0
2 years ago
Take some time to do some research about small businesses in your area. Select one and using HTML design a simple site that educ
lina2011 [118]

Answer:

All you have to do is whright about it

Explanation:

3 0
3 years ago
Other questions:
  • What security protocol originally came with 802.11 equipment?
    11·1 answer
  • What are some good editing software apps for pc?
    11·1 answer
  • Your client expresses that they want their new website to have a responsivedesign with consistent coding. They are concerned wit
    5·1 answer
  • (It science question)
    9·1 answer
  • 2. What is the layout of the modern keyboard known as?
    13·1 answer
  • Write syntactically correct Javascript code to sort an array of sub-arrays containing integers using the sort and reduce array f
    11·1 answer
  • What are the three control statements in Qbasic?​
    10·1 answer
  • The Uniform Electronic Transmission Act (UETA) a. declares that e-signatures are invalid. b. has only been adopted in a handful
    8·1 answer
  • 5. Write the name of the tab, command group, and icon you need to use to access the
    11·2 answers
  • How to transfer polygon from eth to polygon in ledger live
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!