Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can I convert a float array to Byte array?
Posted

This is called serialization. You apparently need binary serialization into array of bytes used for many purposes. You need to use the class System.BitConverter, http://msdn.microsoft.com/en-us/library/system.bitconverter.aspx[^].

It allows you to convert to byte a single float element using GetBytes(Single) or GetBytes(Double).

To do the whole thing, you need first serialize the length of the float array using GetBytes(Int32), then serialize all float members in loop and concatenate all together (for example, use Array.Copy). Pre-create the resulting array at once with the length sizeof(Int32) + ArrayLength*sizeof(Double) (or sizeof(Single)).

You will probably need to right a matching deserialization method — from array of byte to array of float (using ToInt32, ToDouble or ToSingle).

—SA
 
Share this answer
 
v4
1. What is your language C#/VB/anything else?
2. Please provide a detail scenario; what you want to do?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900