Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 2, Problem 2.78HW
Write code for a function with the following prototype:
/* Divide by power of 2. Assume 0 <= k < w-1 */
int divide_power2(int x, int k);
The function should compute x/2k with correct rounding, and it should follow the bit-level integer coding rules (page 128).
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Language: C
Write the definition of the function
bool odd (unsigned char data);
which checks is the value passed to the function is odd or not by returning true or false, respec-
tively. The function has to use bitwise operators and is not allowed to use arithmetic operators.
Need help for SML programming lagauge. (Going from binary to decimal)
I need a function called decimal (val decimal = fn: string -> int) that takes a bit string corresponding to an integer and returns the decimal value of that integer. For example, decimal "10001" returns 17, decimal "001101" returns 13.
I've already done a decimal to binary though the function:
fun binary(x)= if x<=1 then Int.toString(x) else binary(x div 2) ^ Int.toString( x mod 2);
None
Chapter 2 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Ch. 2.1 - Practice Problem 2.1 (solution page 143) Perform...Ch. 2.1 - Prob. 2.2PPCh. 2.1 - Prob. 2.3PPCh. 2.1 - Practice Problem 2.4 (solution page 144) Without...Ch. 2.1 - Prob. 2.5PPCh. 2.1 - Prob. 2.6PPCh. 2.1 - Prob. 2.7PPCh. 2.1 - Prob. 2.8PPCh. 2.1 - Practice Problem 2.9 solution page 146 Computers...Ch. 2.1 - Prob. 2.10PP
Ch. 2.1 - Prob. 2.11PPCh. 2.1 - Prob. 2.12PPCh. 2.1 - Prob. 2.13PPCh. 2.1 - Prob. 2.14PPCh. 2.1 - Prob. 2.15PPCh. 2.1 - Prob. 2.16PPCh. 2.2 - Prob. 2.17PPCh. 2.2 - Practice Problem 2.18 (solution page 149) In...Ch. 2.2 - Prob. 2.19PPCh. 2.2 - Prob. 2.20PPCh. 2.2 - Prob. 2.21PPCh. 2.2 - Prob. 2.22PPCh. 2.2 - Prob. 2.23PPCh. 2.2 - Prob. 2.24PPCh. 2.2 - Prob. 2.25PPCh. 2.2 - Practice Problem 2.26 (solution page 151) You are...Ch. 2.3 - Prob. 2.27PPCh. 2.3 - Prob. 2.28PPCh. 2.3 - Prob. 2.29PPCh. 2.3 - Practice Problem 2.30 (solution page 153) Write a...Ch. 2.3 - Prob. 2.31PPCh. 2.3 - Practice Problem 2.32 (solution page 153) You are...Ch. 2.3 - Prob. 2.33PPCh. 2.3 - Prob. 2.34PPCh. 2.3 - Practice Problem 2.35 (solution page 154) You are...Ch. 2.3 - Prob. 2.36PPCh. 2.3 - Practice Problem 2.37 solution page 155 You are...Ch. 2.3 - Prob. 2.38PPCh. 2.3 - Prob. 2.39PPCh. 2.3 - Practice Problem 2.40 (solution page 156) For each...Ch. 2.3 - Prob. 2.41PPCh. 2.3 - Practice Problem 2.42 (solution page 156) Write a...Ch. 2.3 - Practice Problem 2.43 (solution page 157) In the...Ch. 2.3 - Prob. 2.44PPCh. 2.4 - Prob. 2.45PPCh. 2.4 - Prob. 2.46PPCh. 2.4 - Prob. 2.47PPCh. 2.4 - Prob. 2.48PPCh. 2.4 - Prob. 2.49PPCh. 2.4 - Prob. 2.50PPCh. 2.4 - Prob. 2.51PPCh. 2.4 - Prob. 2.52PPCh. 2.4 - Practice Problem 2.53 (solution page 160) Fill in...Ch. 2.4 - Practice Problem 2.54 (solution page 160) Assume...Ch. 2 - Compile and run the sample code that uses...Ch. 2 - Try running the code for show_bytes for different...Ch. 2 - Prob. 2.57HWCh. 2 - Write a procedure is_little_endian that will...Ch. 2 - Prob. 2.59HWCh. 2 - Prob. 2.60HWCh. 2 - Prob. 2.61HWCh. 2 - Write a function int_shifts_are_arithmetic() that...Ch. 2 - Fill in code for the following C functions....Ch. 2 - Write code to implement the following function: /...Ch. 2 - Write code to implement the following function: /...Ch. 2 - Write code to implement the following function: / ...Ch. 2 - You are given the task of writing a procedure...Ch. 2 - Prob. 2.68HWCh. 2 - Write code for a function with the following...Ch. 2 - Write code for the function with the following...Ch. 2 - You just started working for a company that is...Ch. 2 - You are given the task of writing a function that...Ch. 2 - Write code for a function with the following...Ch. 2 - Write a function with the following prototype: /...Ch. 2 - Prob. 2.75HWCh. 2 - The library function calloc has the following...Ch. 2 - Prob. 2.77HWCh. 2 - Write code for a function with the following...Ch. 2 - Prob. 2.79HWCh. 2 - Write code for a function threefourths that, for...Ch. 2 - Prob. 2.81HWCh. 2 - Prob. 2.82HWCh. 2 - Prob. 2.83HWCh. 2 - Prob. 2.84HWCh. 2 - Prob. 2.85HWCh. 2 - Intel-compatible processors also support an...Ch. 2 - Prob. 2.87HWCh. 2 - Prob. 2.88HWCh. 2 - We are running programs on a machine where values...Ch. 2 - You have been assigned the task of writing a C...Ch. 2 - Prob. 2.91HWCh. 2 - Prob. 2.92HWCh. 2 - following the bit-level floating-point coding...Ch. 2 - Following the bit-level floating-point coding...Ch. 2 - Following the bit-level floating-point coding...Ch. 2 - Following the bit-level floating-point coding...Ch. 2 - Prob. 2.97HW
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Rewrite the temperature conversion program of Section 1.2 to use a function for conversion.
C Programming Language
What are the six common steps needed to access databases from a typical program?
Modern Database Management (12th Edition)
Describe the difference between reading a file with the operator and with the getline function.
Starting Out with C++: Early Objects
Why might doctors and nutritionists be interested in a device like DietSensor?
Using MIS (10th Edition)
Write Java statements to accomplish each of the following tasks: Use one statement to decrement the variable X ...
Java How To Program (Early Objects)
When displaying a Java applet, the browser invokes the _____ to interpret the bytecode into the appropriate mac...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- The H matrix should differ each time the code runs. Please provide a solution without using LLMsarrow_forward****************************** ********** Q4} For the following function f(x)=Sin(x) - Cos(x)+x. Write the mat lab commands to: 1.Draw the function in [-II, II]. 2.Find the zeros of this function. 3. Find the minimum value of function. 4. Find f(1/2) 5.integration the function.arrow_forwardPlease explain your solutionarrow_forward
- Computer Science it has to be done in c programming // Task 3 // For this function, you must return the largest power of 2 that// is less than or equal to x (which will be positive). You may// not use multiplication or some sort of power function to do this,// and should instead rely on bitwise operations and the underlying// binary representation of x. If x is 0, then you should return 0.unsigned largest_po2_le(unsigned x) {return x;}arrow_forwardWrite a function that prints the ASCII values of the char- acters using the following header: void printASCII(char ch1, char ch2, int numberPerLine) This function prints the ASCII values of characters between ch1 and ch2 with the specified number of characters per line. Write a test program that prints 6 ASCII values per line of characters from 'a' to 'm'.arrow_forwardNeed SML help: Define a function called binary (val binary = fn: int -> string) that takes an integer n as an argument and returns a string corresponding to the 16-bit binary representation of that integer. For example, binary 17 returns "0000000000010001". You need not account for numbers whose binary representation requires more than 16 bits.arrow_forward
- Write in C++ program: Problem: Represent the binary representation of a float type to integer type. Single precision float (32-bit length) is represented in IEEE754 format: 1 bit of sign, 8 for exponent plus bias of 127, and 23 for the mantissa. Example: * 85.125 is [101 0101.001] in binary and this would be [1.0101 0100 1 x 2^6] in scientific notation of base 2. * Our sign bit will be [0] (positive), exponent+bias is [1000 0101] (6 + 127 = 133), and mantissa of [0 1010 1001000...] (whole is omitted and zeroes are added to the right until its length is 23). * Merging this will be [0100 0010 1010 1010 0100 0000 0000 0000] which is equivalent as 1118453760 in integer. * Therefore, binary of 85.125 in float is 1118453760 in integer. Input A single line containing a float type non-positive number. 85.125 Output A single line containing the integer representation of float type binary. 1118453760arrow_forwardDefining a binary number as Program 1, write the function int binToDec(const int bin[]) to convert an eight-bit unsigned binary number to a nonnegative decimal integer. Do not output the decimal integer in the function. Test your function with interactive input. Defining bAnd, bin1, and bin2 as binary numbers as in Program 1 above, write the void function void binaryAnd(int bAnd[], const int bin1[], const int bin2[]) to compute bAnd as the logical AND of the two binary numbers bin1 and bin2. Do not output the binary number in the function. Test your function with interactive input. Program1 in C: #include <stdio.h>int main(){int binNum[8]; // Array to read binary numberlong dec=0,n=0; // variables used to convert binary to decimalint k=0,l=0;long binary=0;int i=1,j=0,remainder=0; //reading the binary number in to the array binNumprintf("Please Enter the first binary number with each bit seperate by at least one space : \n"); scanf("%d %d %d %d %d %d %d…arrow_forward(a) Write a function with the header: unsigned long factorial Func( const unsigned long n) that gets the positive integer n and calculates n! n! = n*(n-1)* (n-2)* (n-3) ... * 3 * 2 * 1; (b) The trigonometric function sin(x) can be approximately calculated using the following formula, where n! is factorial(n) - for example 3!=3*2*1 = 6 (the function in previous problem). sin z = (−1)n (2n + 1)! 2n+1 = 0 3! 5! for all c The more terms we use in the series, the higher will be accuracy of the calculations. By using infinite terms in the series we will have the exact value. Write a program that gets x and calculates sin(x) using 5, 10, 20 terms.arrow_forward
- Using C programPlease expalin your code clearly and show outputarrow_forwardWrite a C-function with two arguments (n and r) that has prototype: char clearbit(char k, char bits) The function clears (sets to 0) the bit number k (in the range of 0 to 7) in bits and returns the resulting value. For example, if k is 0x02 and bits is 0x07, the function would return bits with its k’th bit cleared, resulting in 0x03. It must not change other bits in bits. Hint: You may use any number of C-statements, but this task can be accomplished in as few as one!arrow_forwardA company wants to transmit data over the telephone but is concerned that its phones may b tapped. It has asked you to write a program that will encrypt the data so that it may be transmitted more securely. All the data transmitted is 4 digit integers. Your program should read a four digit integer entered by the user and calls a function encrypt which takes four digits as arguments and encrypt it as follows . Replace each digit with the result of adding 4 to the digit and getting the remainder after dividing the new value by 10. . Calls another function swap which swaps the first digit with the third, and second digit with the fourth using pass by reference. Then it prints the encrypted integer.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
CPP Function Parameters | Returning Values from Functions | C++ Video Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=WqukJuBnLQU;License: Standard YouTube License, CC-BY