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
Create a program in Matlab that prints the numbers from 1-100.
Burka [1]

Answer:

numbers = 1:1:100;

for num=numbers

remainder3 = rem(num,3);

remainder5 = rem(num,5);

 

if remainder3==0

disp("Yee")

else

if remainder3 == 0 && remainder5 == 0

disp ("Yee-Haw")

else

if remainder5==0

disp("Haw")

else

disp("Not a multiple of 5 or 4")

end

end

end  

end

Explanation:

  • Initialize the numbers variable from 1 to 100.
  • Loop through the all the numbers and find their remainders.
  • Check if a number is multiple of 5, 3 or both and display the message accordingly.
4 0
3 years ago
Assume your sketch has a variable named silo, which stores an object that is defined by a class you have created. The name of th
yulyashka [42]

Answer:

c. let v = silo.volume();

Explanation:

When you create and initialize a new object you pass through that object's class constructor. The constructor is in charge of initializing all the necessary variables for that class including radius and height. Once you save the object in a specific variable (silo) you need to call the class methods through that variable, using the '.' command. Therefore, in this scenario, in order to call the volume() method you would need to call it from the silo object and save it to the v variable, using the following statement.

let v = silo.volume();

7 0
2 years ago
Which two functions can be used with the math module?
GrogVix [38]

Answer: The math module presents two angle conversion functions: degrees() and radians() , to convert the angle from degrees to radians and vice versa. For example, the following statements convert the angle of 30 degrees to radians and back (Note: π radians is equivalent to 180 degrees).

Explanation: Hopefully this helps you. It is a full answer.

5 0
3 years ago
In Python, what is returned when evaluating [n for n in range(10) if n % 2]?​
Firlakuza [10]
First we need to understand what "n for n in range(10)" means. Basically, we are iterating through all the values n that are in the range of 10 (meaning 0, 1, 2, 3, ..., 9).

Next we are evaluating if n%2. The percentage sign is used to represent modulus which is the remainder of when two numbers are divided. In this case, we are dividing n by 2, and the remainder is our result. When dividing by 2, the only possible remainders are 0 or 1, which when used in an if statement represent the boolean vlaues false and true, respectively. We are doing this calculation for each n from 0 to 9, and if the result is true, we output n to an array.

The numbers that will result in true (a remainder of 1) are the odds numbers. For example, 4/2 = 2 with nothing left over while 5/2 = 2 with 1 left over.

So the following is returned:

[1, 3, 5, 7, 9]
8 0
3 years ago
A canister is released from a helicopter 500m above the ground. The canister is designed to withstand an impact speed of up to 1
Lisa [10]

Answer:

a) h = 1/2 gt² b) 99 m/s c) 14.1 m/s

Explanation:

a) As the only force acting on the canister once released is gravity, as it is constant, we can use one of the kinematic equations, as follows:

h = h₀ + v₀t + 1/2a t²

As we are told that the canister is simply released, it means that v₀ =0.

If we choose the direction of the acceleration (downward) as positive ,and we select the height at which it was released as our origin, so h₀ =0, the final expression for height is as follows:

h = 1/2 g t²

b) Combining this equation with the expression of t, from the definition of acceleration as the rate of change of velocity, we arrive to this expression:

vf² - v₀² = 2 g h  

As v₀ = 0, we have v₀ = √2.g.h = √2.9.8.500 m²/s² = 99 m/s

c) In order to be able to break the canister, impact speed must be larger than 100 m/s.

So, we can use the same equation as above, putting vf=100 m/s, and solving for v₀, as follows:

v₀² = vf² - 2.g.h = 100² m²/s² - 2.9.8.500 m²/s² = 200 m²/s²

v₀ = √200 m²/s² = 14.1 m/s

For any value of v₀ just barely larger than this, the canister will be broken.

7 0
3 years ago
Other questions:
  • What is the car on the right?
    7·1 answer
  • Write a program that asks the user to input four numbers (one at a time). After the four numbers have been supplied, it should t
    6·1 answer
  • What file may contain data written to it in case of an unexpected error or program shut-down?
    5·1 answer
  • A hub or ____ is a central point that connects several devices in a network together.
    11·1 answer
  • Word processing software, spreadsheet software, database software, and presentation software are examples of what category of co
    12·1 answer
  • If you are working on a document and want to have Word automatically save the document every minute, what steps should you use t
    13·1 answer
  • A _____ is a harmful program that resides in the active memory of a computer and duplicates itself. Select one: a. scareware b.
    7·1 answer
  • Brainly app won't let me watch ads anymore. I search my question and there is no skip button to watch an ad it only makes me buy
    7·2 answers
  • Which tool uses images and other visual elements to provide artistic
    9·1 answer
  • 3.8 LAB: Read values into a list
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!