Use the command line to create a new directory called lab21 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.
Binary Real
In Emacs, create a text file called binary_real.txt. In that file answer the following questions on binary real numbers.
What is the binary number 0. 01 in decimal?
What is the the binary number 1010. 0101 in decimal?
What is the decimal number 1. 5 in binary?
What is the decimal number 14. 5625 in binary?
What is the binary number 1. 0 × 101 in decimal?
What is the binary number 0. 10 × 1010 in decimal?
For each of the following numbers, specify whether it can be represented exactly with a python float value.
1 / 3
1 / 4
π
910
91000
1234567890. 0
12345678901234567890. 0
What is the result of evaluating the expression
0.3 == 0.1 + 0.2
in Python?What is the result of evaluating the expression
round(2.675, 2)
?
Base Conversion
Create a Python function called to_decimal(binary_real)
in a file called binary_real.py. The function should have one parameter, binary_real
, that is a string that represents a binary real number. The function should return a float that is the equivalent of the binary string. Assume that the binary_real
string contains only one period character and any number of zero and one characters. Be sure to include test cases for your function.
Submission
Please show your source code and run your programs for the instructor or lab assistant. Only programs that have perfect style and flawless functionality will be accepted as complete.