Question: python Part I: Convert Decimal Format to Binary Fixed-point Format (20 points) Write a function decimalto.fixed.point that takes only one argument, a string called value
python Part I: Convert Decimal Format to Binary Fixed-point Format (20 points) Write a function decimalto.fixed.point that takes only one argument, a string called value that contains a decimal number that could be positive or negative and which includes a fractional part. The function converts the decimal number into its fixed-point binary representation and returns the new representation. The function should generate exactly 23 digits to the right of the radix point. More on this below. CSE 101 Fall 2017 Lab #10 Page 1 Here is the general idea of how to perform the conversion. First, separate off the whole number portion of the value (i.e., those digits to the left of the decimal point) and convert that part into binary. (Hint: use split ( and bin Then, separate off the fractional part i.e, those digits to the right of the decimal point) and convert that part into binary using the multiplication algorithm covered on slide 44 of the Unit 10 lecture notes. You should perform exactly 23 multiplications by the number 2 in order to generate the needed 23 digits. You may assume that only a negative sign might appear at the start of a number, never a positive sign. You might find the following Python functions useful bin ( ) : https://docs.python.org/3/library/functions.html#bin int () : https://docs.python.org/3/library/functions.html#int float () : https://docs.python.org/3/library/functions.html#float . split ( ) : https://docs.python.org/3.6/library/stdtypes.html#str split (Hint: split on , ') Examples on eturn Value decimal.to.fixed point ('-1 decimal-to-fixed-point 7, 4') decimal-to-fixed-point(,-0.00625,) decimalto.fixed point (-0.0') 1100.001000000000 111.01100110011001100110011 ,-0.00000001100 1 1 0011001100, ,-0.00000000000 000000000000, |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
