Assume A = 2.5 and B = 5.25
a) Represent A and B in custom 10-bit floating-point representation with
5 bits for exponent with a bias of 15, 4 bits for the fraction and 1 bit for the sign
b) Compute A - B using the FP add algorithm.
c) Convert your result back to decimal and verify that your answer is correct, which
means it is equal to -2.75
Share
a) To represent A = 2.5 and B = 5.25 in custom 10-bit floating-point representation with 5 bits for exponent, 4 bits for fraction, and 1 bit for the sign, we can follow these steps:
1. Convert A and B to binary:
A = 2.5 = 10.1
B = 5.25 = 101.01
2. Normalize A and B:
A = 10.1 x 2^0
B = 101.01 x 2^0
3. Determine the exponent bias (15 in this case).
4. Represent A and B in the floating-point format:
A = 0 10000 0101
B = 0 10010 0101
In the above representation, the first bit represents the sign (0 for positive, 1 for negative), the next 5 bits represent the biased exponent, and the last 4 bits represent the fraction.
b) To compute A - B using the floating-point add algorithm, we need to align the exponents and then subtract the fractions:
Given: A = 0 10000 0101, B = 0 10010 0101
1. Align the exponents:
A = 0.010000 x 2^3
B = 0.10101 x 2^2
2. Adjust the fraction of A and B to have the same exponent:
A = 0.010000 x 2^3
B = 0.001010 x 2^3
3. Subtract the fractions:
A - B = 0.010000 - 0.001010 = 0.010000 - 0.001010 = 0.001110
4. Normalize the result:
A - B = 0.001110 x 2^3
c) To convert the result back to decimal and verify if it is equal to -2.75:
1. Convert the binary result to decimal:
0.001110 x 2^3 = 0.1110 = 0.875
2. Apply the sign:
Since A - B is negative (as B > A), the result is -0.875.
3. Multiply the result by 2 raised to the power of the biased exponent:
-0.875 x 2^3 = -7.0
Thus, our final result is -7.0, which is not the expected -2.75. It seems there might be an error in the calculations or in the provided A and B values.