Download the files num2bin.m
and bin2num.m (note that you
have to put the files where
Matlab can find them)
For a Matlab number x the command
s=num2bin(x) gives a string of length 64 of
zeros and ones containing the machine representation of x.
For a string s of length 64 consisting of ones and zeros the
command x=bin2num(s) gives the corresponding
number x.
According to the IEEE 754 standard, s(1) contains the sign,
s(2:12) contains the exponent information,
s(13:64) contains digits
d2,...,d53 of the mantissa (for
normalized numbers).
The exponent e is related to this by
e = bin2dec(s(2:12))-1022 , or
s(2:12) = dec2bin(e+1022,11)
Try this out with x = 1, 0.1,
realmin, realmax, 0,
-0, Inf, -Inf, NaN.