How do I convert an array of floats to a byte[] and back?

后端 未结 4 699
臣服心动
臣服心动 2020-12-02 15:38

I have an array of Floats that need to be converted to a byte array and back to a float[]... can anyone help me do this correctly?

I\'m working with the bitConvert

4条回答
  •  旧巷少年郎
    2020-12-02 16:14

    You are not moving the position when you copy the float[i] into the byte array, you should write something like

    Array.Copy(BitConverter.GetBytes(float[i]),0,res,i*4);
    

    instead of just:

    ret = BitConverter.GetBytes(floats[i]);
    

    the inverse function follow the same strategy.

提交回复
热议问题