Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Reference Lab2.c #include #include #include #define SIZE 32 // maximum size of the binary number is 32 bit. // Define the prototypes for functions used
Reference Lab2.c
#includeThe numbers used in the computer system is the binary number system. But we have different data types and need to have different formats to process different data types. In this lab, we will see how the floating-point numbers can be processed with a C program. Part 1: Programming Still use the lab2.c file you have from last week, finish function options 3 and 4 in this lab. Option 2: When you input an 8-bit binary string, you should be able to print its decimal number in a signed format. The size of the binary string should be 8-bit. For example, if your input is 11111111, you should output -1 on the screen. If your input is 10000001, you should print -127 on screen. Option 3: When you input a 32-bit binary string, you should be able to print its floating- point number. The size of the binary string should be at least 8-bit. For example, if your input is 11000001010010000000000000000000, you should print -12.5 on screen. If your input is 01000001010101000000000000000000, you should print 13.25 on the screen. (Hint: if the 32-bit input of this option is not easy, try to predefine the above strings as constants in #define derivative and used it directly in your code. i.e., #define number1 "11000001010010000000000000000000" #define number2 "01000001010101000000000000000000" And then use strcpy(inputs, numberl) to replace statement scanf("%s", &inputs) in option 3.)#include #include #define SIZE 32 // maximum size of the binary number is 32 bit. // Define the prototypes for functions used in the code. /* Prototypes Definitions*/ void printbinary(int number); void convert_binary_to_signed(char *binary); void convert_binary_to_float(char *binary); char *menu = " " \ " " \ "=================================================================== " \ "************Please select the following options******************** " \ " * 1. Convert Integer Number to Binary. (Lab 2) * " \ " ******************************************************************* " \ " * 2. Binary number to signed decimal number conversion.(Lab 3) * " \ " * 3. Binary number to Floating number conversion (Lab 3) * " \ " ******************************************************************* " \ " * e. To Exit, Type 'e' * " \ " ******************************************************************* "; // *Lab 2*. The code needs to convert unsigned number into 32-bit binary format and // display it on screen. For example, if input number is 14, you // should be able to display 00000000000000000000000000001110 on the screen. If input number is 256, you // should display 00000000000000000000000100000000 on the screen. See the screen shot on the lab manual as // a reference of 32-bit display example. // Function to convert decimal number into 32-bit binary and display. void printbinary(int number) { } // Function to convert a binary input into a signed decimal number. // Lab 3 void convert_binary_to_signed(char *binary) { } // Function to convert a 32-bit binary input into a floating number. // Lab 3 void convert_binary_to_float(char *binary) { } // No need to touch main function in lab 2 and lab 3. int main(void) { char options; // the option should only be a byte char inputs[33] = {0}; // 32-bit string plus a ending indicator. int decimal_in = 0; do{ puts(menu); /* prints Memory Simulation */ fflush(stdin); // clear the input buffer before getchar. options = getchar(); switch (options) { case '1': // lab 2 Convert an integer number to binary and display puts("Please input your integer decimal number:"); scanf("%d", &decimal_in); printbinary(decimal_in); continue; case '2': /* lab 3. Convert binary number into a SIGNED decimal number and display */ puts("Please input your BINARY number, "\ "I will convert it to signed decimal:"); scanf("%s", &inputs[0]); // Input must be a string with 0/1 convert_binary_to_signed(inputs); continue; case '3':/* lab 3. Convert 32-bit binary number into a floating * point number number and display */ puts("Please input your 32-bit floating point number " \ "in binary, I will convert it to decimal"); scanf("%s", &inputs[0]); // Input must be a string with 0/1 convert_binary_to_float(inputs); continue; case 'e': puts("Code finished, exit now"); return EXIT_SUCCESS; default: puts("Not a valid entry, exit now"); continue; } }while (1); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started