Practice Problem 2.42 (solution page 156)
Write a function divl6 that returns the value x/16 for integer argument x. Your function should not use division, modulus, multiplication, any conditionals (if or ?:), any comparison operators (e.g., <, >, or ==), or any loops. You may assume that data type int is 32 bits long and uses a two’s-complement representation, and that right shifts are performed arithmetically.
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)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Problem Solving with C++ (10th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
C How to Program (8th Edition)
Database Concepts (8th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- (Practice) a. To convert inches (in) to feet (ft), the number of inches should be multiplied by which of the following conversion factors? i. 12 in/1 ft ii. 1 ft/12 in b. To convert feet (ft) to meters (m), the number of feet should be multiplied by which of the following conversion factors? i. 1 m/3.28 ft ii. 3.28 ft/1 m c. To convert sq.yd to sq.ft, the number of sq.yd should be multiplied by which of the following conversion factors? i. 1 sq.yd/9 sq.ft ii. 9 sq.ft/1 sq.yd d. To convert meters (m) to kilometers (km), the number of meters should be multiplied by which of the following conversion factors? i. 1000 m/1 km ii. 1 km/1000 m e. To convert sq.in to sq.ft, the number of sq.in should be multiplied by which of the following conversion factors? i. 144 sq.in/1 sq.ft ii. 1 sq.ft/144 sq.in f. To convert minutes (min) to seconds (sec), the number of minutes should be multiplied by which of the following conversion factors? i. 60 sec/1 min ii. 1 min/60 sec g. To convert seconds (sec) to minutes (min), the number of seconds should be multiplied by which of the following conversion factors? i. 60 sec/1 min ii. 1 min/60 secarrow_forward(Practice) Run Program 7.10 to determine the average and standard deviation of the following list of 15 grades: 68, 72, 78, 69, 85, 98, 95, 75, 77, 82, 84, 91, 89, 65, and 74.arrow_forward4 We consider the following initial value problem for two functions y(x),z(x): 0=y′′+(y′+6y)cos(z), 5z′=x^2+y^2+z^2, where 0≤x≤2 and y(0)=1.7, y′(0)=−2.7, z(0)=0.5. Approximate the solution of this initial value problem using Euler's method with 100 steps. (use Maple) What approximation value do you obtain for y(2) and z(1)?arrow_forward
- Problem 2. Evaluate the expressions in each of the following triples: (c) 3 (mod4) = 10 (mod4) = 3·10 (mod4) =arrow_forward5. (a) Write a function that solves the general linear least-squares problem. The inputs to your function should be a vector of a values, a vector of measured y values, and an anonymous function that calculates a single row of the Z matrix. Inside your function, use the inputted anonymous function to create Z row-by-row, then use Z to create the normal equations. Solve these normal equations to obtain the computed coefficients that define the best-fit of your model. Your function should output these calculated coefficients. Again, include an error check that makes sure the input vectors are the same size. You may not use any built-in MATLAB functions to solve the normal equation. You can use any functions you have developed solves Ax = b via LU-decomposition is one option. e.g. a function you have that (b) Test your function in (a) to fit the following model to the given dataset (see belo y = a + bx (c) Test your function in (a) to fit the following model to the given dataset…arrow_forwardGeneral math) a. Write a C++ program to calculate and display the midpoint coordinates of the line segment connecting the two endpoints given in Exercise 1a. Use the fact that the coordinates of the midpoint between two points with the coordinates x1,y1)and(x2,y2)are((x1+x2)/2,(y1+y2)/2). Your program should produce the following display (replacing the underscores with values your program calculates): ThexmidpointcoordinateisTheymidpointcoordinateis b. How do you know the midpoint values your program calculates are correct? c. After verifying the output your program produces, modify it to determine the midpoint coordinates of the line connecting the points (2,10) and (12,6). d. If your program doesn’t already do so, change its output to this: The x coordinate of the midpoint is xxx.xx The y coordinate of the midpoint is xxx.xx The xxx.xx denotes placing the calculated value in a field wide enough for three places to the left of the decimal point and two places to the right of it.arrow_forward
- Problem 1. Write a C++ function that inputs a positive integer and determines whether it is prime using trial division. Use your function from Problem 1 to write a C++ program for solving each of the following computational problems. For each problem, find the running time function of the algorithm you are using to write the corresponding program. Problem 2. Determine whether 2^? − 1 is prime for each of the primes not exceeding 100. Problem 3. Find as many primes of the form ?^2 + 1, where n is a positive integer, as you can. Note: Problems 2 and 3 are not related to each other. You need to develop a separate program for each problem. Your programs should invoke your function from Problem 1. For Part 1, submit your C++ programs, test results, and make a conclusion.arrow_forwardPROBLEM 12. [TIME ALLOWED = 5 MINUTES] Give the contrapositive and converse of the following proposition: “If it is sunny, then I will go swimming.”arrow_forwardH.W1/ Write an numerical programme to calculate the first derive for the following function y(x)=sin(4x)+cos(4x) in term of an analytic, central, forward and backward differences respectively. using 101 points from x=0 to x=4. and plot the estimates and the actual function derivatives.arrow_forward
- Q.) Do given c and d problem belowarrow_forward3. Simplify the following Boolean functions, using four-variable Kmaps: (a) F (w, x, y, z) = Σ(1, 4, 5, 6, 12, 14, 15) (b) F (A, B, C, D) = Σ(2, 3, 6, 7, 12, 13, 14) (c) F (w, x, y, z) = Σ(1, 3, 4, 5, 6, 7, 9, 11, 13, 15)arrow_forwardComputer Science f(x)= Sin(x) – x 3 + C Where C = Max [0.15, (69/100)] x20, (x is in radian). Apply the false position method three iterations to find the root of the function (Decide the starting values of Xl and Xu yourself)arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr