Input/Output Format Assume we have sign bit, exponent, and fraction individually for every input number. For example, 54

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Input/Output Format Assume we have sign bit, exponent, and fraction individually for every input number. For example, 54

Post by answerhappygod »

Input Output Format Assume We Have Sign Bit Exponent And Fraction Individually For Every Input Number For Example 54 1
Input Output Format Assume We Have Sign Bit Exponent And Fraction Individually For Every Input Number For Example 54 1 (51.34 KiB) Viewed 52 times
Input Output Format Assume We Have Sign Bit Exponent And Fraction Individually For Every Input Number For Example 54 2
Input Output Format Assume We Have Sign Bit Exponent And Fraction Individually For Every Input Number For Example 54 2 (53.92 KiB) Viewed 52 times
Input Output Format Assume We Have Sign Bit Exponent And Fraction Individually For Every Input Number For Example 54 3
Input Output Format Assume We Have Sign Bit Exponent And Fraction Individually For Every Input Number For Example 54 3 (35.42 KiB) Viewed 52 times
Input/Output Format Assume we have sign bit, exponent, and fraction individually for every input number. For example, 54 is represented in IEEE 754 as: Value: Encoded as: Binary: Sign Exponent You entered Value actually stored in float Error due to conversion Binary Representation 4 IEEE 754 Converter (JavaScript), V0.22 010000100101 Hexadecimal Representation 42580000 and we assume we have sign, exponent, and fraction as following as input: • Sign bit (integer): 0 Exponent (integer): 127+5 Fraction (string, 23+2 characters): "1.10110000000000000000000 Mantissa 1.6675 5767168 Fraction is 25 characters, 23 characters for representing IEEE 754 fraction bits, 1 character for representing binary point, and one character for implicit integer 1. So for any number, first two character of fraction are "1.". And the goal is to produce multiplication and addition result in the same form, e.g. sign bit, exponent, and fraction. Addition Algorithm Addition algorithm is done in 4 steps below: 1. Compare exponents and find smaller number. Shift fraction of smaller number to right and increment exponent by one. Continue until exponents are equal. Make sure under any circumstance, Fraction remains 25-character length (discard bits when necessary). Example: Step 1: compare exponents Number A: Sign: 0, Exponent 128, Fraction: 1.10100000000000000000000 Number 8: Sign: 0, Exponent 130, Fraction: 1.01110000000000000000000 B is larger, so we should shift A by 1 bit Step 2: compare exponents Number A: Exponent 129, Fraction: 0.11010000000000000000000 Number 8: Exponent 130, Fraction: 1.01110000000000000000000 B is larger, so we should shift A by 1 bit and compare: Step 3: compare exponents
Step 2: compare exponents Number A: Exponent 129, Fraction: 0.11010000000000000000000 Number B: Exponent 130, Fraction: 1.01110000000000000000000 B is larger, so we should shift A by 1 bit and compare: Step 3: compare exponents Number A: Exponent 130, Fraction: 0.01101000000000000000000 Number B: Exponent 130, Fraction: 1.01110000000000000000000 Exponents are now equal, lets proceed. 2. Add fractions and store result in a new 25-character string. This is a very subtle process and must be done carefully. You could have various strategies for this step, e.g. write a routine to add fractions in string format or convert strings to integer and use add operator. I leave this step to you to use your creativity and find the best approach. Notice that resulting fraction must include binary point character as well. Example: 0.01101000000000000000000 1.01110000000000000000000 1.11011000000000000000000 Result Exponent is the same as B (larger number): 130 Number A Fraction: Number 8 Fraction: Result Fraction: 3. Verify if the number is normalized. If yes, go to the next step, otherwise, shift right and increment exponent or shift left and decrement exponent. In our example, number is already normalized: 1.11011000000000000000000 Result Fraction: Result Exponent: 130 4. Print results fraction, exponent, and sign bit on the screen. Note: Simplify the problem by assuming numbers are positive only.
Practice 1 Develop a C++ application to implement floating point addition algorithm explained above. Use the example above for verifying the correctness of your solution. Use following skeleton to start off your code: #include <iostream> #include <string> int main() 1 // first input: 3.25 int A sign 0: int A exponent = 128; std::string A fraction="1.10100000000000000000000"; std::cout << "1st input:" "sign: " << A sign << exponent: " << A exponent << " fraction " << A fraction << std::endl; // second input: 11.5 int B sign 0: int 8 exponent = 130; std::string B fraction="1.01110000000000000000000"; std::cout << "2nd input:" sign: " << B sign << " exponent: " << B_exponent << "fraction " << B fraction << std::endl; // implement addition algorithm here // Print sign, exponent, and fraction of final result. return 0; Verify your implementation is correct by comparing against expected result below: Sign: 0. • Exponent: 10000010 • Fraction: 1.1101100000000000000000 What to submit on Moodle? Submit your C++ code. Practice 2 Verify your code with negative numbers and get it working for following example: Number A: Sign: 0. Exponent 131, Fraction: 1.011100000000000 Number B: Sign: 1, Exponent 130, Fraction: 1.10000000000000000000000 The expected result is: Result: Sign: 0, Exponent 130, Fraction: 1.01100000000000000000000 What to submit on Moodle? Submit your C++ code.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply