FF2D00000002000010419000001AAAAA830702000A08140B11030303C0BA4048D0D76F180000B5000000033CFFFF2B00000002000010240000188AAAAA81200A08140B1B1D0303C011E6499096F51828003301000003F8FF 从版本号到数据字段的各个字节的不带进位累加和。计算时,先将校验和字段
填0x00,计算后,再将校验和写入该字段。
红色的是版本号
绿色的校验和
填0x00,计算后,再将校验和写入该字段。
红色的是版本号
绿色的校验和
解决方案 »
- 读取二代身份证上面的相片,这个函数GetBmp(char * Wlt_File,int intf) 怎么用?
- js 调用CS的方法
- 请教Port通讯问题!!!
- Ftp还没有搞定!
- 关于web应用程序中如何使用scrollbar的问题,高手请进!
- 如何用自己的struct去分析一个二进制文件的struct
- winfrom 程序在使用的过程中有一定几率出现程序崩溃,求解
- 如何制作一个录音功能,两天内结贴
- 各位帮我编辑一下这个程序,看看问题在哪里
- C#,winform,窗口中多个仪表控件默认为隐藏,怎么通过读取配置文件中仪表数量来将隐藏的控件显示出相应个数
- c#数据库编程中,是采用OLE DB还是其他方式更好?
- 窗体的命名有什么要求呢?是不是需要前缀呢? 比如按钮一般是 btn打头。 我想问,窗体有要求吗?一般是以什么打头呢?
byte checkcode=0; //存储检验数据
for(int i=5;i<lenth-2;i++) //5为起始计算位置
{
checkcode+=Content[i]; //Content表示需要计算的字节数组
}
Content[lenth-2]=checkcode;大意如此
private void button1_Click(object sender, EventArgs e)
{
//FF2D00000002000010419000001AAAAA830702000A08140B11030303C0BA4048D0D76F180000B5000000033CFF
//FF2B00000002000010240000188AAAAA81200A08140B1B1D0303C011E6499096F51828003301000003F8FF
//string strver = "FF2D00000002000010419000001AAAAA830702000A08140B11030303C0BA4048D0D76F180000B5000000033CFF";
string strver = "FF2B00000002000010240000188AAAAA81200A08140B1B1D0303C011E6499096F51828003301000003F8FF";
byte[] bver = new byte[strver.Length / 2];
for (int i = 0; i < (strver.Length / 2); i++)
{
//倒数第二个字节为0
if (i == (strver.Length / 2) - 2)
{
bver[i] = 0;
}
else
{
bver[i] = HexToByte(strver.Substring(i * 2, 2));
}
}
bool blfind = false;
byte icheck = 0;
for (int i = 0; i < bver.Length; i++)
{
if (!blfind && bver[i] == 2)
{
blfind = true;
icheck = bver[i];
}
if (blfind)
{
icheck = (byte)(icheck + bver[i]);
}
}
//倒数第二位填写校验和
bver[(strver.Length / 2) - 2] = (byte)(0xff & icheck);
string str = ToHexString(bver);
}
private static byte HexToByte(string hex)
{
if (hex.Length > 2 || hex.Length <= 0) throw new ArgumentException("hex must be 1 or 2 characters in length"); byte newByte = byte.Parse(hex, System.Globalization.NumberStyles.HexNumber); return newByte; }
private static string ToHexString(byte[] bytes)
{
string hexString = string.Empty;
if (bytes != null)
{
StringBuilder strB = new StringBuilder(); for (int i = 0; i < bytes.Length; i++)
{
strB.Append(bytes[i].ToString("X2"));
}
hexString = strB.ToString();
}
return hexString;
}
bver[(strver.Length / 2) - 2] = icheck;
str就是含校验码的返回值
string str = ToHexString(bver);
for (int i = 0; i < bver.Length; i++)
{
if (!blfind && bver[i] == 2)
{
blfind = true;
icheck = bver[i];
}
if (blfind)
{
icheck = (byte)(icheck + bver[i]);
}
}
应该为
for (int i = 0; i < bver.Length; i++)
{
if (!blfind && bver[i] == 2)
{
blfind = true;
}
if (blfind)
{
icheck = (byte)(icheck + bver[i]);
}
}
不然会重复加了个2循环次数是bver.Length和bver.Length-1没有区别,因为最后一个字节FF不会影响计算