how to convert a 16-bit or 64-bit signed floting point to binary

masters~ now I'm facing a problem that i have to convert some signed floating point numbers to binary, like -4.182068393394077e-04, or 1.3489.
do anybody have some idea or advices?
thanks

5 Comments

MATLAB does not have any 16 bit floating point representation -- only 32 bit and 64 bit.
please fogive my english and pleas tell me what the type like -4.1xxxxxe-04 called in english. is it called signed 16-bit floating point number?
It is not a question of you English, but it is currently not clear, what you mean by "16-bit floating point" type.
i don't know what it called in english. what is the type of the number -4.4367e-04 called in english? floating poiont? signed?
I have never encountered an unsigned floating point representation. I have encountered unsigned fixed point representations.
The closest you could get to -4.4367e-04 with a signed floating point representation would be to use a scheme with 1 sign bit, 5 exponent bits, 1 "hidden bit", and 10 bits of mantissa. That would allow you to express -(836/1024 + 1) / 2^12, or approximately -4.4346E-04. Notice this only gives you a few decimal places.
5 digits of accuracy requires 16 or 17 bits and the bits for the exponent. 1 sign bit, 5 bits of exponent, 1 hidden bit, 15 bits of mantissa = 21 bits of representation.

Sign in to comment.

Answers (2)

dec2bin(typecast(TheNumber, 'uint16'), 16) - '0'

16 Comments

thanks a lot. i will try it latter. the output of dec2bin is strings so how to convert them to binary stream? or array is okey
Subtracting '0' like I show converts it to binary.
thanks for your help but there still a question, how to covert it back
Look in the code of dec2bin and bin2dec. All you need can be found there.
i have read them but dec2bin's output is an string, after 'string - '0' ' they change to a matrix. how to change them back to dec floating point?
To convert back, add '0', and take char() of that result, then bin2dec()
i have tried it and found that the length of input and out put are not the same. wo convert a 12*1 vector to binary and de-convert it, the output is a 24*1 vector
i will show you the code:
input = [0.9415 0.0491 0.2430 -0.0980 -0.0491 -0.0491 0.0491 -0.0980 0 0 0.0491 -0.1467]
a = dec2bin(typecast(input,'uint32'),32) - '0';
output = bin2dec(char(a + '0'));
input is a 12*1 vector
output will come out a 24*1 vector
please help.
You need to typecast() the output back to double.
output = typecast( bin2dec(char(a + '0')), 'double');
hey frined, id didn't work. i still used the input metioned before, the the output was a 24*1 vector, and the values were wrong either
output = typecast( uint32(bin2dec(char(a + '0'))), 'double');
thank you very much. master...
hey friend, there's another question, how to control the output? Currently the output is a matrix which depends on the the type I typecasted,right?
I am hoping for a 1*N vector or N*1, both okey. if i could be, i will convinient for me to plug it in the frame which i use to input the channel encoder
You need binary for the channel encoder. That is
dec2bin(typecast(TheNumber, 'uint16'), 16) - '0'
You can reshape() that to vector form. Just be sure to reshape() it back before using bin2dec() to convert the binary to numeric form.
i would try this tonight, thanks

Sign in to comment.

What exactly is a "binary stream"? It could be a vector of doubles, which contains only ones and zeros. Of a vector of type LOGICAL, or UINT8. Or remember, that all numbers are stored in binary format on a computer, so perhaps this is enough already:
x = pi;
x_bin = typecast(x, 'uint8')

2 Comments

thank you so much. the friend upside gave me a code so i convert a vector of floating point to a vector which only ones and zeros. what could i do to convert it back~
couas i want to convert a celp parameter vector into binary stream so that i could input it to a Turbo encoder to do some tests for my graduation design. is that clear about "binary stream"?

Sign in to comment.

Categories

Asked:

on 28 Mar 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!