Explanation of Solution
Function definition for compute the high product of signed and unsigned number:
The implementation for “signed_high_prod()” function and “unsigned_high_prod()” function is given below:
//Header file
#include <stdio.h>
#include <assert.h>
#include <inttypes.h>
//Function definition for signed high product
int signed_high_prod(int x, int y)
{
//Compute the product of "x" and "y"
int64_t prod = (int64_t) x * y;
/* Returns result after performing right shift operation */
return prod >> 32;
}
//Function definition for unsigned high product
unsigned unsigned_high_prod(unsigned x, unsigned y)
{
//Declare and assign value for sign "x"
int sx = x >> 31;
//Declare and assign value for sign "y"
int sy = y >> 31;
/* Call signed_high_prod function to compute the signed product of "x" and "y" */
int sProduct = signed_high_prod(x, y);
//Returns the final result
return sProduct + x * sy + y * sx;
}
/* Function definition for theoretical method to compute the unsigned high product */
unsigned alternative_unsigned_high_prod(unsigned x, unsigned y)
{
//Compute the product of "x" and "y"
uint64_t prod = (uint64_t) x * y;
/* Returns result after performing right shift operation */
return prod >> 32;
}
//Main function
int main(int argc, char* argv[])
{
/* Define the value of "x" and "y" in unsigned data type */
unsigned xValue = 0x24680084;
unsigned yValue = 0xFFFFFFFF;
/* Call function with checking value using "assert" function */
assert(alternative_unsigned_high_prod(xValue, yValue) == unsigned_high_prod(xValue, yValue));
return 0;
}
The given code is used to compute the high product of “x” and “y” for signed and unsigned number...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Computer Systems: Program... -Access
- Given a positive integer, check whether it has alternating bits: namely,if two adjacent bits will always have different values.For example:Input: 5Output: True because the binary representation of 5 is: 101.Input: 7Output: False because the binary representation of 7 is: 111.Input: 11Output: False because the binary representation of 11 is: 1011.Input: 10Output: True because The binary representation of 10 is: 1010.""" # Time Complexity - O(number of bits in n)def has_alternative_bit(n): first_bit = 0 second_bit = 0 while n: first_bit = n & 1 if n >> 1: second_bit = (n >> 1) & 1 if not first_bit ^ second_bit: return False else: return True n = n >> 1 return True # Time Complexity - O(1)def has_alternative_bit_fast(n): mask1 = int('aaaaaaaa', 16) # for bits ending with zero (...1010) mask2 = int('55555555',.arrow_forwardGiven a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. For example: Input: 5 Output: True because the binary representation of 5 is: 101. Input: 7 Output: False because the binary representation of 7 is: 111. Input: 11 Output: False because the binary representation of 11 is: 1011. Input: 10 Output: True because The binary representation of 10 is: 1010. """ # Time Complexity - O(number of bits in n) def has_alternative_bit(n): first_bit=0 second_bit=0 whilen: first_bit=n&1 ifn>>1:.arrow_forwardA Gray code is a sequence of binary numbers with the property that no more than 1 bit changes in going from one element of the sequence to another. For example, here is a 3-bit binary Gray code: 000, 001, 011, 010, 110, 111, 101, and 100. Using three D flip-flops and a PLA, construct a 3-bit Gray code counter that has two inputs: reset, which sets the counter to 000, and inc, which makes the counter go to the next value in the sequence. Note that the code is cyclic, so that the value after 100 in the sequence is 000.arrow_forward
- We can perform logical operations on strings of bits by considering each pair of corresponding bits separately (called bitwise operation). Given two eight-bit strings A = 10110001 and B = 10101100 , evaluate the eight-bit result after the following logical operations: ORarrow_forwardWrite an assmbly language program that does the following in MPLABX:• Copy 0x0a into r18.• Use operations on r18 to copy bits 3, 2 and 1 of r18 into the least significant bits ofr19, r20, r21. For example, r19 would equal 0x01 since bit 3 of 0x0a is 1.arrow_forwardSuppose we are given the following subset of code words,created for a 7-bit memory word with one parity bit: 11100110,00001000, 10101011, and 11111110. Does this code use even or oddparity? Explain.arrow_forward
- Consider a hypothetical 8 bit floating point machine representation with a sign bit, a 3 bit exponent, and a 4 bit mantissa (se1e2e3b1b2b3b4), where the exponent bias is 3 (add 3 to exponent of number to form machine representation). Recall that actual mantissa has 5 bits, since the leading 1 is not stored on the machine. (a) What is the number ?≈2.718 in this 8-bit format? (b) What is the number that (10100111)2 represents in this 8-bit format? (c) What is the upper bound of the relative error when representing a real number in this 8-bit format?arrow_forwardScenario: In a biased N-bit binary number system with bias B, positive and negative numbers are represented as their value plus the bias B. For example, for 5-bit numbers with a bias of 15, the number 0 is represented as 01111, 1 as 10000, and so forth. Biased number systems are sometimes used in floating point mathematics. Consider a biased 8-bit binary number system with a bias of 12710 Question: What is the representation and value of the most negative number?arrow_forwardConsider the following floating point representation where each number has 2exponent bits and 5 fraction bits. The exponent bias is 1. Round each number tohave 3 fraction bits. Apply round-to-even and round-toward-zero modes.a. 1 10 11100b. 0 00 00101c. 1 01 10101i. Can you see a pattern for rounding floating point numbers when thenumber of exponent bits are intact?arrow_forward
- If an unsigned 8-bit integer were to be extended to a 16-bit one, the first 8 most significant bits (MSB) would be filled with ones, creating a signed 16-bit representation. Pick a solution from these two options: Is it true or false that...?arrow_forwardWe can perform logical operations on strings of bits by considering each pair of corresponding bits separately (called bitwise operation). Given two eight-bit strings A = 10110001 and B = 10101100 , evaluate the eight-bit result after the following logical operations: XORarrow_forwardThe latest super-duper supercomputer has memory locations that are 64-bits wide. What is the largest unsigned integer that can be stored in one memory location? Suppose that we use sign-magnitude for storing negative numbers and dedicate one bit for a sign bit. What would be the largest POSITIVE integer that can be stored in a memory location.arrow_forward
- 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