IEEE 754 Floating Point Numbers in Computer Systems


Programming Fundamentals
Assignment 1 (10%)
Floating Point Numbers in Computer Systems
[Deadline: 23:59:00 Sunday 31st March 2019]
Background
In C++, decimal numbers are represented as “floating point” numbers according to the IEEE 754 standard. Basically, a floating point number is represented using base 2 scientific notation in a form 2x * y. A variable with “float” data type in C++ uses 32 bits. Its format is represented as follows:

(Source: S. William (2012), Computer Organization and Architecture: Designing for Performance, 9/E, Prentice Hall.)
The 32 bits are divided into three parts:
1.Sign of significand (S) – 1 bit
The left-most bit stores the sign of the number. 0 means positive and 1 means negative.
2.Biased exponent (E) – 8 bits
It forms the value of x in the base 2 scientific notation. A 8-bit number gives a range 0 – 255. This number has to be subtracted by 127 (called biased notation) to obtain the actual value range (i.e., between -127 and 128, inclusive). For example, 0 means -127, 1 means -126 and 255 means 128.

3.Significand (or mantissa) (M) – 23 bits
It forms the value of y in the base 2 scientific notation. The most significant bit is always assumed to be 1 and it is not included in the significand bits. For example, the 23 bits are 00110010000000000000000. So, y equals 1.0011001 (base 2).

IEEE 754作业代做、代写C++课程设计作业

The followings are some concrete examples for illustrating the idea:

Example 1:
0 10000000 00000000000000000000000
= +1 x 2(128 - 127) x 1.0 = 2

Example 2:
0 10000001 10100000000000000000000
= +1 x 2(129 - 127) x 1.101 = 6.5

Example 3:
1 10000001 10100000000000000000000
= -1 x 2(129 - 127) x 1.101 = -6.5
If you are not familiar with binary number and its conversion, visit the following website:
http://www.purplemath.com/modules/numbbase.htm
What you have to do
Write a C++ program to interpret the base 10 value of an input 32-bit binary bit string, represented in IEEE 754 format. From Example 3 above, when the user input
11000000110100000000000000000000
the program should able to interpret it as -6.5.

Program Details
When the program is run, it first prompts for a 32-bit string, as shown below (with a sample input):

Then, the sign, exponent and significand bits are displayed separately.

A user menu is displayed with a number of commands. The user chooses a command by entering the command letter, e.g., ‘S’ or ‘s’ for “Show the Sign”. Below are the details of the each command.
Show the Sign (+/-) (S)
This command shows the sign, ‘+’ or ‘-’, of the number.

Show the biased Exponent in base 10 (E)
This command shows the exponent (no subtraction by 127 is needed here) in base 10 representation.

Show the Significand in base 10 (M)
This command shows the significand in base 10 representation.

Show the value in base 10 (V)
This command shows value of the floating point number in base 10 representation.

Enter a new 32-bit string (N)
This command prompts the user for a new 32-bit string and displays the three parts.

This new binary string will replace the previous one and subsequent enquiries will use this string for interpretation.
Exit the program (X)
The program is terminated. “Bye!” is displayed on the screen.
If any one of the commands (except “Exit the program”) is completed, the program will display the command menu and prompt for a new command again.
Assessment
This assignment is divided into multiple levels of difficulty. Try to accomplish the assignment from the easiest level first and proceed to the next level. It helps you break down the problem into smaller pieces and build up the program progressively. You will be awarded a maximum mark for each level. Only if you complete all requirement of this assignment, you will get full marks.

Level 1 (25 marks)
Prompt for the 32-bit string. (5 marks)
Display the function menu and prompt for function input. (15 marks)
Exit the program. (5 marks)
Level 2 (30 marks)
Show the three parts of the 32-bit string. (15 marks)
Show the Sign. (5 marks)
Enter a new 32-bit string. (10 marks)
Level 3 (45 marks)
Show the biased Exponent in base 10. (15 marks)
Show the Significand in base 10. (15 marks)
Show the value in base 10. (15 marks)
At the beginning of your program, type your information using the following C++ comment template:
//============================================================================
// Author : <your full name>
// Student No. : <your student number>
// Description : COMP1011 Assignment 1
//============================================================================
Warning: Any compilation error will be awarded ZERO mark, regardless of what you have coded. Therefore, if you are unable to complete the whole program, try to accomplish some of the commands and make sure it can be compiled and run successfully.

Assumptions
For the whole assignment, we assume that:
-the user must input a 32-bit string;
-the input from the user is always an integer if the required input is an integer and always a character if the required input is a character.

In other words, you do not have to perform data validation for above cases. You may think about other invalid input and perform proper data validations. E.g., what if the user input a command letter ‘y’?
Note and Hints
1.The input 32-bit string is a character string. You may use a character array (c-string) or a string variable to store the value and write codes to extract the three parts and interpret the values.
2.Using library functions to perform binary-to-decimal conversion is prohibited, you have to write the code by yourself.
Submission
Follow the steps below:
1.Create a folder and name it as <student no>_<your name>.
E.g., 12345678d_CHANTaiMan
2.Name the .cpp file as A1_<student no>_<your name>.cpp.
E.g., A1_12345678d_CHANTaiMan.cpp
3.Put the .cpp file into the folder.
4.Compress the folder (.zip, .7z, .rar, or .jar) and submit the compressed file to Blackboard.
Any wrong file naming and submission will be given ZERO mark in this assignment. If you are using Windows, the file extension may be hidden by the operating system. Follow the steps of below links to make sure the file extension is not hidden:
Windows XP, 7 & 8: https://www.howtohaven.com/system/show-file-extensions-in-windows-explorer.shtml
Windows 10: http://kb.winzip.com/kb/entry/26/
There are a maximum of 5 attempts for submission. Only the last attempt will be assessed.
The deadline of this assignment is 23:59:00 Wed 7th March 2018. No late submission is allowed.
This assignment is an individual work. All work must be done on your own. Plagiarism is serious offence. The Moss (https://theory.stanford.edu/~aiken/moss/) system will be adopted for plagiarism checking. Submissions with high similarity, in terms of code patterns and structures, in addition to direct-copy-and-paste, will be treated as plagiarism. Copying code from web resources is prohibited as well. Any plagiarism cases (both copier and copiee) will be given ZERO mark in this assignment.

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codinghelp

猜你喜欢

转载自www.cnblogs.com/metojava/p/10573811.html