如何在二进制文件中添加字节? [英] How to add Bytes in a binary file?

查看:153
本文介绍了如何在二进制文件中添加字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



我有一个二进制文件。它是摩托罗拉s37格式。

我的工作是读取二进制文件中的每一行,并验证每行中的校验和。

我是给出样本

如何计算checkSum的例子。



校验和计算

以下示例记录:



S1137AF00A0A0D0000000000000000000000000061

被解码以显示校验和值的计算方式如下:



添加:添加每个字节13 + 7A + F0 + 0A + 0A + 0D + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 = 19E (十六进制)总数。

掩码:保持总数的最低有效字节= 9E(十六进制)。

补语:计算最低有效字节的补码= 61( hex)。



我需要在C#中实现上述功能。你可以帮我解决

Hello All,

I have one Binary file. It is in motorola s37 format.
My Job is to read each and every line in a binary file and to verify the check sum in each and every line.
I am giving the sample
example that How to calculate checkSum.

Checksum calculation[edit]
The following example record:

S1137AF00A0A0D0000000000000000000000000061
is decoded to show how the checksum value is calculated as follows:

Add: add each byte 13 + 7A+F0 + 0A+0A+0D+00+00+00+00+00+00+00+00+00+00+00+00+00 = 19E (hex) total.
Mask: keep the least significant byte of the total = 9E (hex).
Complement: compute ones' complement of least significant byte = 61 (hex).

I need to Implement above in C#. Could you please Help me out

推荐答案

这样做,S37(或正确知道的SREC)并不复杂:https://en.wikipedia.org/wiki/SREC_(file_format) [ ^ ]



所有你需要做的就是:

1)读取每一行

2)剥去行标题字节(S0,S1等)

3)拉出文件内校验和,并将其转换为一个字节

4)将每对十六进制数字读成一个字节。

5)求所有字节。

6)补充金额。

7)将计算出的值与之前处理的in = file值进行比较。

8)继续( 2)下一行。



这并不复杂:但这是你的功课,所以我不会给你任何代码!
So do it, S37 (or SREC as it is properly known) isn't complicated: https://en.wikipedia.org/wiki/SREC_(file_format)[^]

All you have to do is:
1) Read each line
2) Strip off the line header bytes ("S0", "S1", etc.)
3) Pull out the in-file checksum, and convert it to a byte
4) Read each pair of hex digits into a byte.
5) Sum all the bytes.
6) Complement the sum.
7) Compare the calculated value with the in=file value you processed earlier.
8) Continue from (2) with the next line.

This isn't complex: but it's your homework, so I'll give you no code!

这篇关于如何在二进制文件中添加字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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