Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

16
Feb

IEEE 754 Binary Floating Point Representation

Related Blog Items

How the floating point values are stored?

Note:  Please note that this discussion is not related to the C Language.

To be able to represent floating point numbers in the bit pattern, one needs
to know about IEEE 754, the floating point specification.  So, read patiently.

IEEE Floating Point Format:
---------------------------

    3 3          2         1         0
    1 09876543 21098765432109876543210
    +-+--------+-----------------------+
    |s| be     |       fraction        |
    +-+--------+-----------------------+

    be - biased exponent.  It is a constant, 127, for 32-bit
         floating point number.  This is also know as
         Mantisa(M).

    The general form of a floating point number is:
    x = s * M * B^p

        where,  s is sign bit
                M is normalized mantissa (1.fffff for IEEE 754)
                B is base ( 2 for IEEE 754 )
                p is integer power (explained below)

                ^ stands for exponentiation

    (Note: The 1 of 1.fffff is not explicitly stored in the memory)

    The general form would be: x = s * 1.ffff .. fff (binary) * 2^p

    This would not solve the problem unless an example or two are given.

    Example 1:  Convert 5.75 to binary floating point.

    The integer part is 101.
    The fractional part is found by

        0.75 * 2    =   1.5     (1)
        0.5  * 2    =   1.0     (1)
        0.0  * 2    =   0.0     (0)   so it terminates

    So, the number is 101.110
    This is the mere binary floating point representation of 5.75
    To make it IEEE 754 compliant, we have to have the normalized
    mantissa.

    So,
        101.110 = 1.01110 * 2^2
        therefore, M = 1.01110  and
                   p = 2

        be = p + 127 = 2 + 127 = 129 i.e., 1000 0001 (binary)
        The fractional part is 0.01110...

    So, the IEEE 754 representation of 5.75 becomes:

        0 1000 0001 01110 0000 0000 0000 0000 000

    Example 2:  Convert -0.1 to binary floating point

    The fractional part is found by

        0.1  * 2    =   0.2     (0)
        0.2  * 2    =   0.4     (0)
        0.4  * 2    =   0.8     (0)
        0.8  * 2    =   1.6     (1)
        0.6  * 2    =   1.2     (1)
        0.2  * 2    =   0.4     (0)     which repeats 0.2 above
        0.4  * 2    =   0.8     (0)
        0.8  * 2    =   1.6     (1)

    So, the fractional part is 0.000110011...

    0.000110011  =  1.1001100 * 2^(-4)
    therefore,  M = 1.1001100
                p = -4

    be = 127 + p = 127 - 4 = 123 i.e., 0111 1011 (binary)
    The fractional part is 1001 1000 ....

    So, the IEEE 754 representation of 5.75 becomes:

        1 01111011 1001 1000 0000 0000 0000 000

Popularity: 29%

You need to log on to convert this article into PDF


Related Blog Items

2 Comments

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image