A.
Explanation of Solution
“C” Expression for “K = 17”:
The C expression to perform the multiplications for “K = 17” is shown below
Expression: (x << 4) + x
A complete program has been developed to perform the multiplication with “K = 17” is shown below:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition for part A that is K = 17
int partA(int x)
{
//Returns the value by using "(x << 4) + x"
return (x << 4) + x;
}
//Main function
int main(int argc, char* argv[])
{
//Assign the value for "x"
int xValue = 0x12345678;
/* Call function "partA" with checking value using assert function */
assert(partA(xValue) == 17 * xValue);
return 0;
}
The given code is used to multiply integer variable “x” by constant factor “K = 17”...
B.
Explanation of Solution
“C” Expression for “K = -7”:
The C expression to perform the multiplications for “K = -7” is shown below
Expression: x - (x << 3)
Program:
A complete program has been developed to perform the multiplication with “K = -7” is shown below:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition for part B that is K = -7
int partB(int x)
{
//Returns the value by using "x - (x << 3);"
return x - (x << 3);
}
//Main function
int main(int argc, char* argv[])
{
//Assign the value for "x"
int xValue = 0x12345678;
/* Call function "partB" with checking value using assert function */
assert(partB(xValue) == -7 * xValue);
return 0;
}
The given code is used to multiply integer variable “x” by constant factor “K = -7”...
C.
Explanation of Solution
“C” Expression for “K = 60”:
The C expression to perform the multiplications for “K = 60” is shown below
Expression: (x << 6) - (x << 2)
Program:
A complete program has been developed to perform the multiplication with “K = 60” is shown below:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition for part C that is K = 60
int partC(int x)
{
//Returns the value by using "(x << 6) - (x << 2)"
return (x << 6) - (x << 2);
}
//Main function
int main(int argc, char* argv[])
{
//Assign the value for "x"
int xValue = 0x12345678;
/* Call function "partC" with checking value using assert function */
assert(partC(xValue) == 60 * xValue);
return 0;
}
The given code is used to multiply integer variable “x” by constant factor “K = 60”...
D.
Explanation of Solution
“C” Expression for “K = -112”:
The C expression to perform the multiplications for “K = -112” is shown below
Expression: (x << 4) - (x << 7)
Program:
A complete program has been developed to perform the multiplication with “K = -112” is shown below:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition for part D that is K = -112
int partD(int x)
{
//Returns the value by using "(x << 4) - (x << 7)"
return (x << 4) - (x << 7);
}
//Main function
int main(int argc, char* argv[])
{
//Assign the value for "x"
int xValue = 0x12345678;
/* Call function "partD" with checking value using assert function */
assert(partD(xValue) == -112 * xValue);
return 0;
}
The given code is used to multiply integer variable “x” by constant factor “K = -112”...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Computer Systems: A Programmer's Perspective Plus Mastering Engineering With Pearson Etext -- Access Card Package (3rd Edition)
- please code in Python.Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. The input will be a non-negative integer.16 --> 1 + 6 = 7 942 --> 9 + 4 + 2 = 15 --> 1 + 5 = 6 1 32189 --> 1 + 3 + 2 + 1 + 8 + 9 = 24 --> 2 + 4 = 6 493193 --> 4 + 9 + 3 + 1 + 9 + 3 = 29 --> 2 + 9 = 11 --> 1 + 1 = 2arrow_forward1a) Give the values of the following: M[i,i+1] for i=1,...,5 M[i,i+2] for i=1,...,4 M[i,i+3] for i=1,...,3 f M[1,5] and M[2,6] M[1,6]. b) How do you place the parentheses to compute A by this number of scalar multiplications? For multiplication from left to right write ((((A1A2)A3)A4)A5)A6. c) How many ways to place the paratheses to compute A are there that achieve the minimum number of scalar multiplications?arrow_forwardUsing Python Write a program using functions to print the prime numbers in a given range [n, m].Example Input:n = 5m = 40Example Output:5, 7, 11, 13, 17, 19, 23, 29, 31, 37arrow_forward
- Suppose that you are given the following logical statement:¬ P ∧ Q → ¬ R ∨ SBased on our discussion of order of operations, which is the correct way to interpretthis?(a) ¬(P ∧ ((Q → (¬R)) ∨ S))(b) (¬(P ∧ (Q → (¬R)))) ∨ S(c) ((¬P) ∧ (Q → (¬R))) ∨ S(d) (¬P) ∧ ((Q → (¬R)) ∨ S)(e) (¬(P ∧ Q)) → (¬(R ∨ S))(f) ((¬P) ∧ Q) → ((¬R) ∨ S)(g) ((¬P) ∧ (Q → (¬R))) ∨ S(h) ((¬P) ∧ (Q → (¬R))) ∨ S(i) (¬P) ∧ ((Q → (¬R)) ∨ S)(j) ¬((P ∧ Q) → (¬(R ∨ S)))arrow_forwardanswer with proper explanation and step by step solution. For the given C code below, indicate the values assigned to each of the variable p, q, r, and s: int p, q, r, s; int i = 4; int j = 5; { int i = 6; p = i + j; } q = i + j; { Int j=7; i = 8; r = i + j; } s = i + j;arrow_forwardFor arbitrary a and b,c % m = (a b) % mc % m = [(a % m) (b % m)] % mUsing this mathematical property, you can iterate 1 to the exponent, recalculating each time by multiplying the current modulus value with the last.Here is the pseudocode:1 Set value = 1, current exponent = 0.2 Increment current exponent by 1.3 Set value = (base value) mod modulus until current exponent is reached exponentExample: Base: 4, Exponent: 3, Modulus: 54ˆ3 % 5 = 64 % 5 = 4value = (lastValue x base ) % modulus:value = (1 x 4) % 5 = 4 % 5 = 4value = (4 x 4) % 5 = 16 % 5 = 1value = (1 x 4) % 5 = 4 % 5 = 4write javascript code ?arrow_forward
- (B) Write a program that reads from the user the values of x and h to implement the equation below. -10x + 2h, √x -h, fx = x < 3 x ≥ 3arrow_forwardCode in Python. Suppose an upward force of air resistance on a free-falling object is proportional to the square of velocity. In this case, the speed can be calculated by (img) where cd is the second-order drag coefficient. If g=9.81m/s² , m=68.1kg , and cd=0.25kg/m, calculate, using a Python program and numerical integration, how much the object falls in 10s . Use a number of intervals large enough to have at least three decimal places of precision.arrow_forwardWhat would be the output of the following program?Please note that the operation x % 10 (i.e., x modulo 10) is always the same as the rightmost digit of x (e.g., 123 % 10 = 3).arrow_forward
- Rewrite the following arithmetic expressions to take advantage of concurrent processing by usingthe terms COBEGIN and COEND. X := (A * 2B)^2 / (C + D)^(E + F) .arrow_forwardWe usually write numbers in decimal form (or base 10), meaning numbers are composed using 10 different “digits” {0,1,…,9}.{0,1,…,9}. Sometimes though it is useful to write numbers hexadecimal or base 16. Now there are 16 distinct digits that can be used to form numbers: {0,1,…,9,A,B,C,D,E,F}.{0,1,…,9,A,B,C,D,E,F}.So for example, a 3 digit hexadecimal number might be 2B8. How many 2-digit hexadecimals start with a letter (A-F) or end with a numeral (0-9) (or both)?arrow_forwardprocedure Horner(c, a_(0), a_(1), a_(2),… , a_(n): real numbers)y := a_(n)for i := 1 to ny := y ∗ c + a_(n−i)return y {y = a_(n)c^(n) + a_(n−1)c^(n−1) + ⋯ + a_(1)c + a_(0)}a) Evaluate 3x^(2) + x + 1 at x = 2 by working througheach step of the algorithm showing the values assigned at each assignment step.b) Exactly how many multiplications and additions areused by this algorithm to evaluate a polynomial ofdegree n at x = c? (Do not count additions used toincrement the loop variable.)arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning