Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here, you will be writing a program to read in integers positive and negative-, and represent them in twos complement formthe way the computer stores

Here, you will be writing a program to read in integers positive and negative-, and represent them in twos complement formthe way the computer stores them and does arithmetic with themand floating point numbers. In particular, you will be writing a C program that will do the following:

1) Function ReadNos: Read numbers from a text file. There will be one file that contains decimal integers and floating point numbers interspersed (cp3.txt). What distinguishes integers from floating point numbers is that floating point numbers have a decimal point (e.g. 1.0 is a floating point number whereas 1 is an integer. Numbers can be positive or negative. Numbers will be separated by white spaces and an end of file (EOF) will end the numbers. I recommend you read in each number as a string, or as an array of characters. However, it is your choice. You may assume that each number can be no more than 16 characters, including the decimal point.

2) Function ConvertDecimal2Binary: After reading in a decimal number, the program must convert it into the appropriate binary form. For a decimal integer, it is to be converted into its 32 bit (signed) twos complement representation. For a floating point number, it is to be converted into the single precision IEE floating point format.

3) Function WriteBinaryNos: All numbers converted will be output into a file. A sample output is provided in cp3.out.txt. You may use this file in developing and testing your program. Note that we do insist on splitting the floating point to binary converted output into three parts separated by a space: sign, exponent, and mantissa, as shown in the sample output file cp3.out.txt, so as to make your output easily readable to us. The formatting of the output does not have to be as nice, but if it is, thats 5 bonus points. Note that when we execute your program it will be with a different file with the same name, and it will contain different numbers altogether. You have the choice of additional functions, so long as you document what these functions do, e.g. you may call a different function depending in whether the number read in is afloating point number versus an integer. However, you are not required to. You will get to decide how many and the data types of the arguments for each function.

CP3.txt file is below

8763.011 0.1 25 -38 1234567890 -1110 -11.0 -13.265 8763.000001 -8763.001

CP3.out is below

The binary representation of decimal 8763.011 is 0 10001100 00010001110110000001011 The binary representation of decimal 0.1 is 0 01111011 10011001100110011001100 The binary representation of decimal 25 is 00000000000000000000000000011001 The binary representation of decimal -38 is 11111111111111111111111111011010 The binary representation of decimal 1234567890 is 01001001100101100000001011010010 The binary representation of decimal -1110 is 11111111111111111111101110101010 The binary representation of decimal -11.0 is 1 10000010 01100000000000000000000 The binary representation of decimal -13.265 is 1 10000010 10101000011110101110000 The binary representation of decimal 8763.000001 is 0 10001100 00010001110110000000000 The binary representation of decimal -8763.001 is 1 10001100 00010001110110000000001

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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