Convert bytes to float values

时光总嘲笑我的痴心妄想 提交于 2019-12-12 05:32:27

问题


I need to convert 28 byte value to a 7 float values, each 4 bytes denote 1 float value. I have to implement this in C#. I searched for lot of solutions, but most of them were in C/Java.


回答1:


Use

System.BitConverter.ToSingle(..)

Like this:

float f1,f2,f3,f4,f5,f6,f7;  
f1 = System.BitConverter.ToSingle(bytearr,0);  
f2 = System.BitConverter.ToSingle(bytearr,4);  
f3 = System.BitConverter.ToSingle(bytearr,8);  
...  
f7 = System.BitConverter.ToSingle(bytearr,24);



回答2:


Like so:

byte b;
float f;
f = (float)b;


来源:https://stackoverflow.com/questions/11773520/convert-bytes-to-float-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!