I show interconversion with floating point and real number.
(* convert to IEEE 754 single precision floating point binary seqence (length: 32) from number *)
real32Digits[x_] :=
IntegerDigits[
First[ImportString[ExportString[x, "Real32"], "UnsignedInteger32"]],
2, 32]
(* generate {Sign, Exp, Mantissa} list from Real 32 binary sequence (except special number) *)
real32Format[li_] :=
{If[First[li] === 0, 1, -1],
FromDigits[Take[li, {2, 9}], 2] - 2^7 + 1,
FromDigits[{Join[{1}, Take[li, {10, 32}]], 1}, 2]}
(* convert to real number from Real32 binary sequence *)
fromReal32Digits[li_] := First[ImportString[ExportString[FromDigits[li, 2], "UnsignedInteger32"], "Real32"]]
Example:
In[1] := real32Digits[-118.625]
Out[1] := {1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0}
In[2]:= real32Format[%]
Out[2] := {-1, 6, 949/512}
In[3] := fromReal32Digits[%%]
Out[3] := -118.625
Mathematica supports floating point representations; Real16, Real32, Real64, and Real128.
refer to
IEEE floating point - Wikipedia, the free encyclopedia
Binary DataWolfram Mathematica 9 Documentation
appendix: Coloring parts of floating point sequence
nLi = IntegerDigits[First[ImportString[ExportString[-118.625, "Real32"], "UnsignedInteger32"]], 2, 32]
sgnLi = Take[nLi, 1]; (* Sign *)
eLi = Take[nLi, {2, 9}]; (* Exp *)
sLi = Take[nLi, {10, 32}]; (* Mantissa *)
Grid[{Join @@ {Item[#, Background -> LightBlue] & /@ sgnLi,
Item[#, Background -> LightGreen] & /@ eLi,
Item[#, Background -> LightRed] & /@ sLi}}]