Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assuming that 12 bits are available to store the relevant operand and the result

ID: 3862380 • Letter: A

Question

Assuming that 12 bits are available to store the relevant operand and the result: a. Show how the compiler can use subtraction and shifting only (that is, no use of multiplication) to determine the result of 19*56, if 19 is the value of a variable, x, and 56 is a constant which is known to the compiler at compilation time. Show the bit patterns of both operands in the multiplication, and explain clearly the steps you follow to determine the result. b. Now show how the compiler can use subtraction and shifting only (that is, no use of multiplication) to determine the result of 19*-56, if 19 is the value of a variable, x, and -56 is a constant which is known to the compiler at compilation time. Show the bit patterns of both operands in the multiplication, and explain clearly the steps you follow to determine the result.

Explanation / Answer

#include<stdio.h>

int main()

{

int x = 19, y1 = 56,y2= -56,output1,output2,i;

output1 = (x<<6);

output2 = (y2<<5);

for(i = 0 ; i<8 ; i++)

{

output1 = output1 - 19;

}

for(i = 0 ; i<13 ; i++)

{

output2 = output2 - (-56);

}

printf("The output of 19*56 is : %d ",output1);

printf("The output of 19*-56 is : %d ",output2);

return 0;

}

========> OUTPUT <=================

The output of 19*56 is : 1064

The output of 19*-56 is : -1064