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
EBK COMPUTER SYSTEMS
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY