Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 3: Decimal to Binary Converter Due Wednesday, Feb 12. The class time on Friday, Feb 7 will be used for discussing, designing, and developing

image text in transcribed

image text in transcribed

Assignment 3: Decimal to Binary Converter Due Wednesday, Feb 12. The class time on Friday, Feb 7 will be used for discussing, designing, and developing of this program. The converter should fulfilled the following requirements: Program naming and formatting o The program is named DecimalToBinary Converter.c o Program header comments like author, description, etc. O Reason amount of in-line comments explaining major steps Program termination o The program should allow user to continue entering integer numbers. Each time an integer is entered, it should display the binary of the integer. o The program should be terminated when random input is entered. Binary representation requirements The binary to be displayed should be of 16-bits (ie, it should consider a 16-bit system) o For negative integer input, the binary to be displayed should be of the 2's complement form. Data validation o The valid range of the input integer should be checked so as to store as a 16-bit binary. If user enters any number outside the range, prompt a message instead of trying to display binary. Algorithm requirements: o The division-remainder algorithm (i.e., keep dividing by two till zero) should be implemented for decimal- to-binary conversion o For negative input, the program should implement all of the following steps to get the 2's complement binary: 1) Convert magnitude to 16-bit binary 2) Flip all bits 3) Add 1 Output requirements o Simulate the following output format closely Enter integers to view its binary form: Non-numeric input terminates program. Integer: @ Binary: eeeeeeeeeeeeeeee Integer: 1 Binary: 0000000000000001 Integer: -1 Binary: 1111111111111111 Integer: 5 Binary: 2088eeeeee00101 Integer: -5 Binary: 1111111111111011 32767 Integer: 32767 Binary: 0111111111111111 32768 The number 32768 is too large to be held in 32-bit binary. -32768 Integer: -32768 Binary: 1000000000000000 -32769 The negative number -32769 is too large to be held in 16-bit binary. random input Submit the following items: 1) The source file (.e., DecimalToBinaryConverter.c) 2) A screen shot of the program and output. The output should contain the minimum test cases of 0, 1,-1,5,-5, 32767, 32768, -32768, -32769, and any other input terminating the program. * Double check all the requirements before you submit. Hints 1. Using a char array to hold the binary is a good idea. Be sure you keep an additional element to hold the terminating character '\0' so that the array can be ended properly. 2. Be careful about the differences between integer 0 or 1, and character (char type) 'O' or '1'. a. The remainder of dividing an integer by 2 is of int type b. Character 'O' or 'l' is of char type, the computer stores the ASCII code 48 for 'o', and 49 for '1'. 3. The following method is an example for arithmetically adding one to the binary simulated by a char array arr. /* addone: arithmatically add 1 to the binary simulated by character array * INPUT: char arr[] : the character array holding the binary int numofBits: the number of bits in the binary void addone(char arr[], int numofBits) { * Trueth table carry arr[i] l arr[i] carry 1 char carry = 'i'; for(int i = numOfBits - 1; i >= ; i--){ if(carry != arr[i]){ arr[i] = 'i'; carry = ''; else if(carry == '1'){ arr[i] = 'a'; else{ arr[i] = ''; return

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

Students also viewed these Databases questions

Question

=+2. How reliable is this existing information?

Answered: 1 week ago

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago