解析csharp中的intel hex文件 [英] parse intel hex file in csharp

查看:206
本文介绍了解析csharp中的intel hex文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个hex文件。我读数据。如果我在第一行读取的字符包含:020000040000FA,并且在某些地方有相同的字符,但最大行包含

:10000000B80C001061020000690200006B020000E1我想从第1行读取然后第二行进一步。并且只想读取第一个跳过的数据块9包含的字符:和它之间的最后2个数据块就像第一行一样:020000040000FA这是0000是数据块并且在同一个第二行中相同:10000000B80C001061020000690200006B020000E1 i此数据块是

B80C001061020000690200006B020000。那么我怎样才能阅读并附加每个行数据块。

解决方案

很难理解你真正想做的是什么。你能否请你改一下你的问题。

看一下 StreamReader 类和子串方法在字符串对象中。


您已经在 c#中的hex文件解析器 [ ^ ]。

但是,昨天我回答了类似的问题,所以这里是转换它的代码:

  int  i =  0 ; 
int index = 0 ;
byte [] hexBytes = new byte [sourceLine.Length / 2];
do
{
string hs = sourceLine.Substring(index , 2 );
hexBytes [i] =( byte int .Parse(hs,System.Globalization。 NumberStyles.AllowHexSpecifier);
i ++;
index + = 2 ;
} while (index < sourceLine.Length);
// hexBytes现在包含已转换的数据



从文件中读取,然后将您感兴趣的字符复制到 sourceLine 中,并使用上面的代码将其转换为原始二进制值。


i have a hex file. i read data.if i am reading as a character in that first line contain :020000040000FA and at some places have same character but maximum lines containing
:10000000B80C001061020000690200006B020000E1 i want to read from 1st line and then second and further on. and want to read only data block that is skip first 9 char included : and last 2 between this have data block like for first line :020000040000FA in this is 0000 is data block and same in same second line :10000000B80C001061020000690200006B020000E1 i this data block is
B80C001061020000690200006B020000. so how may i read and append each line data block.

解决方案

Its hard to understand what it is you really want to do. Can you please rephrase your question.
Take a look at StreamReader class and Substring method in the string object.


You already posted this question at hex file parser in c #[^].
However, I answered a similar query yesterday so here is the code to convert it:

int i = 0;
int index = 0;
byte[] hexBytes = new byte[sourceLine.Length /2];
do
{
    string hs = sourceLine.Substring(index, 2);
    hexBytes[i] = (byte)int.Parse(hs, System.Globalization.NumberStyles.AllowHexSpecifier);
    i++;
    index += 2;
} while (index < sourceLine.Length);
// hexBytes now contains the converted data 


Read from the file and then copy the characters you are interested in into sourceLine and use the above code to convert it to its original binary values.


这篇关于解析csharp中的intel hex文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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