Explanation of Solution
Function definition for “mul3div4()” function:
The implementation for “mul3div4()” function is given below:
//Header file
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//Function definition for divide by power of "2"
int divide_power2(int x, int k)
{
//Determine negation value
int isNegation = x & INT_MIN;
//Check condition
(isNegation && (x = x + (1 << k) - 1));
//Returns value by using "x >> k" that is "x/(2^k)"
return x >> k;
}
//Function definition for mul3div4 function
int mul3div4(int x)
{
//Compute multiply "3"
int m3 = (x << 1) + x;
/* Returns the value of "3 * x/4" by calling function "divide_power2" */
return divide_power2(m3, 2);
}
//Main function
int main(int argc, char* argv[])
{
//Assign the value for "x"
int xValue = 0x87651234;
/* Call function "mul3div4" with checking "x * 3 / 4" value using assert function */
assert(mul3div4(xValue) == xValue * 3 / 4);
return 0;
}
The given code is used to compute the value of “
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
- Need 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_forward4. Using bitwise operators In C code Write a function int negate(int n) that can negate an integer without using the - operator.arrow_forwardcode required in mips programming language a .s or .asm code not a c code. Write a MIPS procedure that takes as its two parameters the starting address of a (zero-terminated) string, and a character c, and removes all instances of the character from the string. Also, write a main program to test your procedure. Your main program should input a string from the user (you can assume that the string will be at most 40 characters, not including the zero byte delimiter), and then prompt for input of a character c. If the character c that the user inputs is the newline character (ascii code 10), your program should terminate. Otherwise, your program should invoke your procedure, output the modified string, and then prompt for input of another character to be removed from the string, continuing in this manner until the input character is the newline characterarrow_forward
- Q6. Write a function that takes an unsigned integer andreturns the number of '1' bits it has(also known as the Hamming weight).For example, the 32-bit integer '11' has binaryrepresentation 00000000000000000000000000001011,so the function should return 3.T(n)- O(k) : k is the number of 1s present in binary representation.NOTE: this complexity is better than O(log n).e.g. for n = 00010100000000000000000000000000only 2 iterations are required.Number of loops isequal to the number of 1s in the binary representation."""def count_ones_recur(n): Do it.arrow_forwardProblem F. 73154. Trailing zeros Input file: Output file: Time limit: Memory limit: standard input standard output 1 second 256 megabytes In this problem, you are given 8-bit number r. Find the number of trailing zeros in its binary representation. Trailing zeros are the ones that we encounter until the first 1-bit if we traverse the binary representation from right to left. For example, the binary representation of the mumber 96 is 01100000. Number of 0-bits until the first 1-bit is 5 (considering that we traverse the binary representation from right to left). Input The first line of input contains a single number z – 8-bit number (1arrow_forwardIn c++ Now write a program for a double floating pointtype.•What are the number of significant bits that the double’s mantissa can hold, excluding the sign bit.•What is the largest number that a double’s mantissa can hold without roundoff error?•Repeat the program shown on the previous page but set to show where the double’s mantissa starts to exhibit roundoff errors.arrow_forwardCAN YOU PLEASE RUN IT IN ONLINE GDB! C language. Write a program using pointers, which based on the adequate functions compute the sum, difference, dot product, or cross product of two vectors in Rn. Write a program using pointers, which based on the adequate functions, computes the sum, difference of multiplication of two matrices in Rm×n.arrow_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_forwardWrite 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_forwardWrite the function int count101(int n) that counts the number of occurrences of the bit pattern 101 in n. It should return the final count. Variable n is 32 bits. Example: Suppose n is just 8 bits, say n=11010101, then the function would return 3.arrow_forwardQuestion VI: Write a program that computes and plots the spectral representation of the function 1. y(t) = (10e-10t)u(t) 2. y(t) = (10e-10t cos100t)u(t)arrow_forwardWrite a C function hwkThree that takes an unsigned integer variable. The variable will contain the encoding for a single precision floating point value in normalized form. Your code should take this value, isolate the 8 most significant bits of the mantissa using bitwise operations, and then return this value in an unsigned char variable Here is the expected function declaration: unsigned char hwkThree(unsigned int value);arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education