Search code examples
binaryfloating-pointieee-754ieee

Half precision conversion


How comes that 0 11110 1111111111 is equal to the half precision format 1.1111111111 * 2^15? Both should be 65504.

The sign bit here is a 0. The exponent would be 11101 and the fractional part 1111111111. But that doesn't look like 1.1111111111 * 2^15 at all.

Can someone explain that to me?


Solution

  • Here is the layout of your half-precision number:

    Number layout

    The exponent's value is 111102, which is 3010. Half-precision numbers have exponent bias of 1510, so we need to subtract 1510 from 3010 to get the actual exponent of 1510.

    There is an implicit 12 pre-pended to the fraction, so the actual fraction has one extra 1 in front of it. The binary fraction point is located immediately after that implicit 1, making the number look like this:

    1.1111111111
    

    In order to apply the binary exponent of 1510, we need to move the fraction point fifteen positions to the right. This produces the number 11111111111000002, which is equal to 6550410 after the conversion.