Task 1: Floating-Point Number Representation
This task is a text-based task but automatically checked. You are required to write your answers into solutions.txt by replacing the question marks with the correct solution. Please, do not change the structure of solutions.txt and be consistent with its syntax (comment-lines start with #)
Task
We examine the normalized binary representation of floating point numbers in the normalized floating point system $F*(2,4,-3,3)$.
-
Convert the following decimal numbers to the normalized binary representation. For each number, choose the appropriate exponent $e$ and round to the nearest value if you cannot represent the exact value. If the exact number falls exactly midway between two bracketing finite floating point representations, round to the number with an even least significant bit.
- \(0.75_{10}\)
- \(3.1416_{10}\)
- \(2.718_{10}\)
- \(7_{10}\)
- \(0.11_{10}\)
- For each number of (2), convert the binary representation back to their decimal form, and determine the absolute rounding error of the conversion.
- Calculate \(2.718_{10} + 3.1416_{10} + 0.11_{10}\) in the binary representation. What do you observe?
Note: The question of how to round floating point numbers is non-trivial. The IEEE standard lists 5 different modes of rounding of which we only mentioned the most common one at the beginning of this exercise. If you are interested to learn more, you can access the most recent standard through the ETH network.
Solution
# NOTE: Lines starting with # are comments. Spaces are ignored.
# Replace the question marks, with your answer, following the instructions
# provided for each subtask.
######################## Subtask 1 ############################
# Subtask 1a: convert 0.75.
# In the given system, this is equal to "1.100 * 2^-1". The solution
# is written as "1.100*2^-1", without spaces and without quotation marks.
1a) 1.100*2^-1
# Subtask 1b: convert 3.1416
1b) 1.101*2^1
# Subtask 1c: convert 2.718
1c) 1.011*2^1
# Subtask 1d: convert 7
1d) 1.110*2^2
# Subtask 1e: convert 0.11
1e) 1.000*2^-3
######################## Subtask 2 ############################
# Convert the first number of previous Sub-Task back to decimal form.
# For each number you are required to write the decimal number and the
# conversion error (each on a different line).
# For your convenience, the first number is already converted.
2a-decimal) 0.75
2a-error) 0
2b-decimal) 3.25
2b-error) 0.1084
2c-decimal) 2.75
2c-error) 0.032
2d-decimal) 7
2d-error) 0
2e-decimal) 0.125
2e-error) 0.015
######################## Subtask 3 ############################
# Calculate the result of the addition and indicate the result in the
# same format as in the first sub-task ("siginificand*2^exp", without
# quotation marks). Then, write your observation as a comment right below.
3) 1.100*2^2
# Write your observations here
# The Decimal System cannot be represented accurately by the binary system. There will always be an error. When adding the number converted from the decimal to the binary sytem, the error becomes greater.
Made by JirR02 in Switzerland 🇨🇭