Question: Finish the 2 C Programming functions below please: #define SIZE 8 // The size of the two numbers to be multiplied is 8-bit. // Define
Finish the 2 C Programming functions below please:
#define SIZE 8 // The size of the two numbers to be multiplied is 8-bit.
// Define the prototypes for functions used in the code. short Booth(const char *input1, const char *input2);
char *menu = " " \ "************Please select the following options******************** " \ " * 1. Booth Algorithm. (Lab 4) * " \ " ******************************************************************* " \ " * e. To Exit, Type 'e' * " \ " ******************************************************************* ";
// This function is to convert a 8-bit string source (with char '1' or '0' // into an integer number; for example, if input is "11111110", it will return decimal number // -2 ; if input is "00001111", if will return 15 in 8-bit. // This function should be similar to the function you finished in Lab 3, option 2.
signed char convert_binary_to_signed(const char *binary) {
}
Write a function to implement Booth's algorithm to multiply two 8-bit signed binary numbers. The returned result should be a decimal number. For example, if input1 is "11111110", input2 is "00001110", the output should be (-2) * 14 = -28. (should be a 16-bit signed binary number)
short Booth(const char *input1, const char *input2)
{ signed short result = 0; // short is 16-bit result. signed char a = 0; // This is A in the algorithm. signed char m = 0; // This is M in the algorithm. signed char q = 0; // This is Q in the algorithm. char q_minus_one = 0; // This is the bit q_minus_one in algorithm. signed int count = SIZE; // This is size of input.
return result; }
// Main function int main(void) { char options; // the option should only be a byte char inputA[SIZE+1] = {0}; // 8-bit multiplicand. char inputB[SIZE+1] = {0}; // 8-bit multiplier. short product = 0; // product should be an unsigned number. // system("cls"); // Supposed to clear the screen now. // But not always working in all system. do{ puts(menu); /* prints Memory Simulation */ fflush(stdin); // clear the input buffer before getchar. options = getchar(); switch (options) { case '1': // lab 4_A input two 8-bit binary numbers and // perform multiplication with Booth's algorithm puts("Please input your multiplicand:"); scanf("%s", &inputA[0]); puts("Please input your multiplier:"); scanf("%s", &inputB[0]); product = Booth(inputA, inputB); // call the Booth algorithm to get the result. printf ("The product of %s and %s is: %d ", inputA, inputB, product); continue; case 'e': puts("Code finished, exit now"); return EXIT_SUCCESS; default: puts("Not a valid entry"); continue; } }while (1); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
