MATLAB: How we can convert negative float value into binary in matlab? Is there any direct command for this

q-1

I am doing my final year project on audio watermarking in which I will be replacing audio bits by text using lsb method. For that I will apply DCT(discrete cosine transform) on wav-audio file. After that I will convert it into binary and replace it's lsb bits by text binary bits. But the problem is that after taking DCT of audio file it gives negative float values and I don't know how to convert those negative float values into binary. Please help me out if you know.

Best Answer

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
%%%%%%%%%%%%%%%%%%%%%