Search code examples
binaryfloating-pointhexieee-754scientific-notation

Convert hexadecimal to IEEE-754 single precision floating point binary scientific notation


I am trying to convert these numbers to binary scientific notation, but I cannot figure out the process. Could someone please the process of going about solving this?

For IEEE 754 single precision floating point, what is the number, as written in binary scientific notation, whose hexadecimal representation is the following?

0061 0000

I can get this converted from hex to unsigned binary:

0000 0000 0110 0001 0000 0000 0000 0000

but I can't figure out how to properly represent this using binary scientific notation. Thanks in advance!


Solution

  • binary32 is broken into 3 sections: sign, exponent (biased) and significand (or fraction).

    0000 0000 0110 0001 0000 0000 0000 0000
    ||        ||                          |
    ||        |\-- significand -----------/
    | \ expo  /
    \ sign
    

    So in this case,

    sign (negative) = 0, so number is positive
    exponent (biased) = 0000 0000
    significand = .1100001 0000 0000 0000 0000
    

    If the exponent (power of 2) is at the highest value (1111 1111), that indicates the number is special: Infinity or Not-a-Number.

    If the exponent is 0, the bias is -126, else the bias is -127 and an implied 1 should be added to the fraction.

    sign = 0 (positive) or +1
    exponent = 0 - 126
    significand = 0.1100001 =  (binary) 1100001/10000000 = 97/128
    
    +1 * pow(2, -126) * 97/128 = 8.9080431273251475213255815711373...e-39
    

    Notes:
    On-line converters available. example
    Endian: the order in which the bytes are to be interpreted can vary. 0061 0000 could be 00 00 61 00. An assumption was made here with this example.