In: Computer Science
Q1: In the addition of floating-point numbers, how do we adjust the representation of numbers with different exponents?
Q2:
Answer the following questions:
1. To add two floating-point numbers firstly rewrite the smaller number such that the exponent matches the exponent of the larger number. For eg
Let's say we are adding 8.75 x 10-1 and 9.32 x 101 (these are in normalized)
So we have to rewrite 8.75 x 10-1 as 0.0875 x 101.
Now add the mantissa of the two numbers 0.0875 + 9.32 = 9.4075.
Now the final answer, in this case, is 9.4075 x 101. If the result of the addition isn't in normalized, you will have to normalize it.
2. To set let's say nth bit you have to left shift 1 till n times and or with the original number to set the nth bit, similarly, if you want to set let's say k bits you will have to create a number with those particular bits set to 1 and then or with the number.
For eg let's say the binary representation of the number is 000010 and you want to set 4th and 5th bit you would or it with 0110000, so the result after or operation will be 011010.
To unset let's say nth bit you have to take the number of the same number of bits as the original number and the bits which you want to unset as 0 and take and with the original number
For eg let's say the binary representation of the number is 011010 and you want to unset the 4th and the 5th bit you will and it with 100111, so the result would be 000010.
For flipping a number just take the negation of the number.
The negation of 000010 will be 111101