The number is 0x4001 8CCC CCCC CCCC
.
So far I have the stored exponent as 1000000000
which equals 2^10
or 1024
.
Stored exponent subtracted by bias number is 2^1
.
I have the mantissa as 1.0001 1000 1100 .... 1100
.
My problem is when I try to compute the 1100
repeating part. How do I represent this?
I know I have to input the remianing repeating decimal part into x
so I can get the correct base 10 value using this forumla: (1 + (1/16 + 1/32 + x) * 2^1
.
Best Answer
The binary64 format of IEEE754 double precision number using 64 bits to represent a floating point number. This representation consists of three pieces:
If you are given a number $X$ with hexadecimal/binary pattern
$$ \require{enclose} \def\xD{{}_{10}} \def\xH{{}_{16}} \def\xB{{}_{2}} \newcommand{\xP}[2][black]{\color{#1}{\enclose{box}{\small\verb/#2/}}} \begin{align} &\xP{4001 8CCC CCCC CCCC}\xH\\ = &\xP{0 - 100 0000 0000 - 0001 0100 1100 1100 1100 1100 1100 1100 1100 1100 1100 1100 1100}\xB \end{align}$$
The sign bit is stored as $\xP{0}\xB = 0$. This means $X$ is positive.
The exponent is stored with binary pattern $\xP{100 0000 0000}\xB = 1024$.
Since the exponent offset is $1023$, the actual exponent for $X$ is $1024 - 1023 = 1$.
The significand is stored with hexadecimal pattern $\xP{1 8CCC CCCC CCCC}\xH$.
Together with the implicit leading $1$-bit, this corresponds to the number
$$1 + \frac{1}{16} + \frac{8}{16^2} + \frac{12}{16^3} + \frac{12}{16^4} + \ldots + \frac{12}{16^{13}}$$
Combine these 3 pieces, the number $X$ is
$$\begin{align} & (+1) \times 2^{1} \times \left[ 1 + \frac{1}{16} + \frac{8}{16^2} + \frac{12}{16^3}\left(1 + \cdots + \frac{1}{16^{10}}\right)\right]\\ = & 2 \left[1 + \frac{1}{16} + \frac{8}{16^2} + \frac{12}{16^3}\left(\frac{1-16^{-11}}{1 - 16^{-1}}\right)\right]\\ = & \frac{1234971460318003}{562949953421312}\\ \approx & 2.1937499999999996447286321199499070644378662109375\ldots \end{align} $$