Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* ============================================================================ Name : Lab2.c Version : Copyright : Copyright 2021 Description : Number conversions in the computer system, Ansi-style ============================================================================ */ #include #include #include

image text in transcribed

/* ============================================================================ Name : Lab2.c Version : Copyright : Copyright 2021 Description : Number conversions in the computer system, Ansi-style ============================================================================ */

#include #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(const int number); void convert_binary_to_signed(const char *binary); void convert_binary_to_float(const char *binary);

char *menu = " " \ " " \ "=================================================================== " \ "************Please select the following options******************** " \ " * 1. Convert An 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 // Function to convert a unsigned number into a 32-bit binary number // Your code should display the binary number 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 screenshot on the lab manual as a reference of 32-bit display example.

void printbinary(const int number) // const makes sure number won't change inside the function. {

system("PAUSE"); return; }

// Lab 3 // Function to convert a binary input into a signed decimal number.

void convert_binary_to_signed(const char *binary) // const makes sure binary string won't change inside the function. {

system("PAUSE"); return;

}

// Lab 3 // Function to convert a 32-bit binary input into a floating number.

void convert_binary_to_float(const char *binary) {

system("PAUSE"); return; }

// No need to touch the main function below in lab 2 and lab 3.

int main(void) { char options; // the option should only be a byte char inputs[SIZE+1] = {0}; // 32-bit string plus an ending indicator. int decimal_in = 0; do{ puts(menu); /* prints Menu Options */ fflush(stdin); // clear the input buffer before getchar. Some compilers need this. 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); // read an integer number from the input. printbinary(decimal_in); // needs to finish this function in lab 2 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 characters 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 characters 0/1 convert_binary_to_float(inputs); continue; case 'e': puts("Code finished, exit now"); return EXIT_SUCCESS; default: puts("Not a valid entry, please choose another option"); continue; } }while (1); }

Refer to lab2.c file posted on blackboard, finish functions to print out a given unsigned/signed number into its binary number. The following screenshots are demos of what you should have on your output screen. Pay special attention to " // finish this part..." comments. Case 1: Input a positive number: . ****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' Please input your integer decimal number: 0000000000000000000000000001100 12 Case 2: Input a negative number (the binary number should be in 2's complement format): **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' 1 Please input your integer decimal number: -20 11111111111111101100 Please follow the following requirements for this lab: 1. Must have your comments on each line of the source code to explain your code. 2. At the start of the source code, you must type in your name and student ID as the comments. 3. Must include the screenshots of at least two integer numbers (one signed and one unsigned

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions

Question

What qualities do you see as necessary for your line of work?

Answered: 1 week ago