MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Yang
on 28 Mar 2013

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

*No products are associated with this question.*

Answer by Walter Roberson
on 28 Mar 2013

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

Show 13 older comments

Yang
on 31 Mar 2013

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

Walter Roberson
on 31 Mar 2013

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.

Answer by Jan Simon
on 28 Mar 2013

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')

Yang
on 28 Mar 2013

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~

## 5 Comments

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/68896#comment_139445

MATLAB does not have any 16 bit floating point representation -- only 32 bit and 64 bit.

## Yang (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/68896#comment_139478

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?

## Jan Simon (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/68896#comment_139536

It is not a question of you English, but it is currently not clear, what you mean by "16-bit floating point" type.

## Yang (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/68896#comment_139548

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?

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/68896#comment_139595

I have never encountered an unsigned floating point representation. I

haveencountered 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

andthe bits for the exponent. 1 sign bit, 5 bits of exponent, 1 hidden bit, 15 bits of mantissa = 21 bits of representation.