This is a function I wrote for my own use long ago. Perhaps you can make use of it or it can give you some ideas. It converts a single scalar 'double' to a string of 53 binary digits, including a binary point, a sign, and an exponent of 2. This representation is precise, giving exactly what is contained in the number as stored in its internal IEEE 754 format.
function s = binstr(x)
if ~finite(x)|(length(x)~=1), error('x must be a finite scalar.'),end
b = (x<0); x = abs(x);
s = zeros(1,53);
[f,e] = log2(x);
for i = 1:53
f = 2*f;
d = floor(f);
f = f - d;
s(i) = d+48;
end
s = ['0.' s sprintf('*2^(%d)',e)];
if b, s = ['-' s]; end
s = char(s);
return
Best Answer