float array to binary string and vice-versa?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello, In order to exchange information with an external application, I need to "pack" an array of numbers into a string, and vice-versa. How can I achieve this? I need to do this with 32bit floats and 32bit unsigned integers.
The external application sends the data like following:
float myFloatArray[4];
char* dataToSend=(char*)myFloatArray;
sendData(dataToSend,4*4); // 4*4 is the size of the data
Data is packed as little Endian.
Thanks for any insight!
1 comentario
Respuestas (2)
José-Luis
el 17 de Mayo de 2013
Editada: José-Luis
el 17 de Mayo de 2013
I don't exactly understand what you are trying to achieve in Matlab. The code you show is C/C++. Also, there are no pointers in Matlab (not explicitely at least). You could save your floats as a binary file, using little endian byte order. There is no need to typecast:
your_float = single(rand(1,4));
%Saving it as binary stream
fid = fopen('myBin.bin','w','l'); %little endian
fwrite(fid,your_float,'single');
fclose(fid);
The you could read that file in your C/C++ code. Or do you actually mean that you want a string of zeros and ones? That is a different thing.
0 comentarios
Ver también
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!