0
$\begingroup$

i'm trying to understand how to add two numbers in IEE754 half precision format , i haven't found a good reference/tutorial on this , so i've tried to follow the 32 bit floating point addition procedure , but at some point i'm stucked , what i know is:

Half precision (16 bit) IEEE 754 floating point number bit configuration is:

1 bit for sign 5 bit for exponent bit and 10 bit for mantissa.

i have two numbers:

1110001000000001 0000001100001111

so i rewrited them as

1 11000 1000000001 0 00000 1100001111

before adding them i have to convert them in normalized binary scientific notation (i don't know if i'm right):

Convert the exponent of the first number in decimal: 24 Subtract bias (that is 15) so i have: 24-15 = 9 so the exponent is 9

so the mantissa is : 1.000000001 * 2^9

But i don't know how to continue , can someone please explain me the correct process for solving this , or link me a good reference/title of a book for understanding this procedure? i'm searching on Google and trying to understand on different books , but i can't clarify this procedure to myself.

$\endgroup$
  • $\begingroup$ How would you proceed for 32 bit numbers and why doesn't it work for 16 bit numbers? $\endgroup$ – adrianN Sep 19 '16 at 13:42
  • $\begingroup$ i'm stuck when i have to make exponents equal , i don't know if it is correct . So assuming that i have the two numbers specified in the answer: <br> if i convert the exponent of the first number in decimal , it is equal to 24 , and the secon exponent is equal to 0? so in order to add the numbers i have to make 0 equals to 24 , this means that i have to shit the second number to right of 23 position? and it becomes 0.0000000000000000000000000000011000011 is that possible? $\endgroup$ – user2158666 Sep 19 '16 at 13:45
1
$\begingroup$

The second number has zero as exponent and has non zero mantissa, so it is a Denormal (aka Subnormals)

0 01111 1100001111 = 1.1100001111 * 2**0   = 1.1100001111
0 01110 1100001111 = 1.1100001111 * 2**-1  = 0.11100001111
0 01101 1100001111 = 1.1100001111 * 2**-2  = 0.011100001111
0 01100 1100001111 = 1.1100001111 * 2**-3  = 0.0011100001111
0 01011 1100001111 = 1.1100001111 * 2**-4  = 0.00011100001111
0 01010 1100001111 = 1.1100001111 * 2**-5  = 0.000011100001111
0 01001 1100001111 = 1.1100001111 * 2**-6  = 0.0000011100001111
0 01000 1100001111 = 1.1100001111 * 2**-7  = 0.00000011100001111
0 00111 1100001111 = 1.1100001111 * 2**-8  = 0.000000011100001111
0 00110 1100001111 = 1.1100001111 * 2**-9  = 0.0000000011100001111
0 00101 1100001111 = 1.1100001111 * 2**-10 = 0.00000000011100001111
0 00100 1100001111 = 1.1100001111 * 2**-11 = 0.000000000011100001111
0 00011 1100001111 = 1.1100001111 * 2**-12 = 0.0000000000011100001111
0 00010 1100001111 = 1.1100001111 * 2**-13 = 0.00000000000011100001111
0 00001 1100001111 = 1.1100001111 * 2**-14 = 0.000000000000011100001111
0 00000 1100001111 = 0.1100001111 * 2**-14 = 0.000000000000001100001111

Denormals have no leading 1 and use the same exponent as smallest normal numbers.

To perform an addition, you need to align mantissas, then perform an addition or a subtraction (if the signs are opposite, as this is the case here.) :

  -1000000001.0
  +         0.000000000000001100001111
 =-1000000000.111111111111110011110001

Here the difference between the two numbers is too large and the small number will disappear after rounding, except if you use a special rounding mode (as round towards zero or towards +infinite)

Maybe you have other sample additions that are more interesting.


Using two's complement, one can make subtractions out of additions :

    -         0.000000000000001100001111
 ! = 1111111111.111111111111110011110000 : Invert all digits
+1 = 1111111111.111111111111110011110001 : plus one.

The addition-that-is-a-subtraction becomes :

     1000000001.000000000000000000000000
   + 1111111111.111111111111110011110001
= [1]1000000000.111111111111110011110001
$\endgroup$
  • $\begingroup$ So in my example i need to perform a subraction in this case? ok you allign mantissas , but how do you get 1's after decimal point in the result? you complemented the number? $\endgroup$ – user2158666 Sep 20 '16 at 15:25
  • $\begingroup$ IEEE numbers are not encoded as two's complement, but as sign&magnitude, if the numbers are of opposite signs, the addition becomes a subtraction : you subtract the small number from the large number, and the result has the large number's sign. A binary subtraction is just like a decimal subtraction. 1000 - 0.0001 = 999.9999, here we have "ones" instead of "nines". $\endgroup$ – TEMLIB Sep 20 '16 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.