An archived instance of discourse for discussion in undergraduate Real and Numerical Analysis.

Generating a number from a 64 bit string

mark

Suppose the sign, mantissa, and exponent of a 64 bit number are given by:
$$0\,\,0100100000000000000000000000000000000000000000000011\,\,00001100100$$
What is the decimal representation of the number?

Shia

I believe the answer is 1.806957261e-278.

I followed the notebook on Floating Point numbers and made a function in Python to read over the string of bits as text and compute what the 64 bit number would equate to.

import numpy as np

def BitStringToFloat(bitString):
    dd = np.zeros(52, dtype=int)
    for bits in range(1,53):
        if bitString[bits]=="1":
            dd[bits-1]=1
    ee = np.zeros(11, dtype=int)
    for bits in range(1,11):
        if(bitString[-bits]=="1"):
            ee[bits-1]=1
    s= 1 if (bitString[0]=="1") else 0
    bins = [2**(-n) for n in range(1,53)]
    c = 1+np.dot(dd,bins)
    bins2 = [2**(n) for n in range(11)]
    e = int(np.dot(ee,bins2)-1023)
    number_from_bin = (-1)**s * c * 2**e
    print(number_from_bin)
    return (s,c,e)
Invictus

Since your sign bit is 0 shouldn't your answer be positive? You have $$(-1)^1$$ instead of $$(-1)^0$$ with how your code is written or you could have just left it as $$s*c*2^e$$ instead of $$(-1)^s$$

Shia

My bad, that typo should be fixed now.