从二进制文件读取排序内存的帮助 [英] help for sort memory read from binary file

查看:108
本文介绍了从二进制文件读取排序内存的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设c中有一个结构,如:
struct
{
浮动fAZ;
float fEL;
int iNo;
int iSubNo;
} my_struct;
同时,记录器将类型为my_struct的数组写入二进制文件;
记录器的特点是,将变调器的低字节先保存到二进制文件中,然后将高字节保存到二进制文件中.
现在,我已经使用filestream类将文件中的数据读取到字节数组中.
我的问题是我如何才能将字节数组重新组织为32bit的原始值,或者在读取二进制文件时必须使用什么策略?
只是一个例子:
这是二进制文件的一部分,总共4 * 32位或16字节
"00 00 20 40""33 33 33 3F""12 00 00 00""00 25 00 00"
将上述数据读入字节数组A后,A中的内容为{00,00,20,40,33,33,33,3F,12,00,00,00,00,25,00,00}. /> 实际上,值"fAZ"为0x40200000,其浮点类型值为2.5
同样,fEL的浮点类型值为0.7(0x3f333333)
如何处理数组A?

Suppose there is a structure in c such as :
struct
{
float fAZ;
float fEL;
int iNo;
int iSubNo;
}my_struct;
Meanwhile a array which type is my_struct is write into a binary file by a recorder;
The characteristics of the recorder is that low bytes of a varibal are saved firstly and high byte secondly into the binary file.
Now I have alreay read the data from file into a byte array through using filestream class.
My question is how can i reorganize the byte array to their origin true values in 32bit or What strategies must be used when reading the binary file?
Just a example:
here is a part of the binary file ,total 4*32 bits or 16 bytes
"00 00 20 40" "33 33 33 3F" "12 00 00 00" "00 25 00 00"
When data above is read into byte array A,content in A is {00,00,20,40,33,33,33,3F,12,00,00,00,00,25,00,00}.
Actualy,the Value "fAZ" is 0x40200000 and its float type value is 2.5
In the same way,the float type value of fEL is 0.7(0x3f333333)
How to deal with array A?

推荐答案

.NET中的字节顺序与您所描述的相同,因此您必须在同一C#中声明结构.方式:

The byte order in .NET is the same as you described, so you will have to declare your structure in C# in the same way:

[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)];
struct MyStruct {
      public float fAZ;
      public float fEL;
      public int iNo;
      public int iSubNo;
}



—SA



—SA


这篇关于从二进制文件读取排序内存的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆