Foxtable(狐表)用户栏目专家坐堂 → [求助]求CRC16 校验码算法例子


  共有9320人关注过本帖树形打印复制链接

主题:[求助]求CRC16 校验码算法例子

帅哥哟,离线,有人找我吗?
111yangguojun
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:243 积分:1928 威望:0 精华:0 注册:2013/8/8 23:49:00
[求助]求CRC16 校验码算法例子  发帖心情 Post By:2014/12/22 18:48:00 [只看该作者]

数据:01 04 00 00 00 0a 校验码:70 0d

 

上面数据与校验码该怎么计算,求高手帮做个小案例,谢谢了!

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/12/22 19:04:00 [只看该作者]

Dim s As String = CRCCheckFile("d:\test.jpg")
Output.Show(s)

 

http://www.foxtable.com/help/topics/1346.htm

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/12/22 19:16:00 [只看该作者]

 全局代码

 

Public CRC16Table As UShort() = {&H0, &H1021, &H2042, &H3063, &H4084, &H50a5, _
 &H60c6, &H70e7, &H8108, &H9129, &Ha14a, &Hb16b, _
 &Hc18c, &Hd1ad, &He1ce, &Hf1ef, &H1231, &H210, _
 &H3273, &H2252, &H52b5, &H4294, &H72f7, &H62d6, _
 &H9339, &H8318, &Hb37b, &Ha35a, &Hd3bd, &Hc39c, _
 &Hf3ff, &He3de, &H2462, &H3443, &H420, &H1401, _
 &H64e6, &H74c7, &H44a4, &H5485, &Ha56a, &Hb54b, _
 &H8528, &H9509, &He5ee, &Hf5cf, &Hc5ac, &Hd58d, _
 &H3653, &H2672, &H1611, &H630, &H76d7, &H66f6, _
 &H5695, &H46b4, &Hb75b, &Ha77a, &H9719, &H8738, _
 &Hf7df, &He7fe, &Hd79d, &Hc7bc, &H48c4, &H58e5, _
 &H6886, &H78a7, &H840, &H1861, &H2802, &H3823, _
 &Hc9cc, &Hd9ed, &He98e, &Hf9af, &H8948, &H9969, _
 &Ha90a, &Hb92b, &H5af5, &H4ad4, &H7ab7, &H6a96, _
 &H1a71, &Ha50, &H3a33, &H2a12, &Hdbfd, &Hcbdc, _
 &Hfbbf, &Heb9e, &H9b79, &H8b58, &Hbb3b, &Hab1a, _
 &H6ca6, &H7c87, &H4ce4, &H5cc5, &H2c22, &H3c03, _
 &Hc60, &H1c41, &Hedae, &Hfd8f, &Hcdec, &Hddcd, _
 &Had2a, &Hbd0b, &H8d68, &H9d49, &H7e97, &H6eb6, _
 &H5ed5, &H4ef4, &H3e13, &H2e32, &H1e51, &He70, _
 &Hff9f, &Hefbe, &Hdfdd, &Hcffc, &Hbf1b, &Haf3a, _
 &H9f59, &H8f78, &H9188, &H81a9, &Hb1ca, &Ha1eb, _
 &Hd10c, &Hc12d, &Hf14e, &He16f, &H1080, &Ha1, _
 &H30c2, &H20e3, &H5004, &H4025, &H7046, &H6067, _
 &H83b9, &H9398, &Ha3fb, &Hb3da, &Hc33d, &Hd31c, _
 &He37f, &Hf35e, &H2b1, &H1290, &H22f3, &H32d2, _
 &H4235, &H5214, &H6277, &H7256, &Hb5ea, &Ha5cb, _
 &H95a8, &H8589, &Hf56e, &He54f, &Hd52c, &Hc50d, _
 &H34e2, &H24c3, &H14a0, &H481, &H7466, &H6447, _
 &H5424, &H4405, &Ha7db, &Hb7fa, &H8799, &H97b8, _
 &He75f, &Hf77e, &Hc71d, &Hd73c, &H26d3, &H36f2, _
 &H691, &H16b0, &H6657, &H7676, &H4615, &H5634, _
 &Hd94c, &Hc96d, &Hf90e, &He92f, &H99c8, &H89e9, _
 &Hb98a, &Ha9ab, &H5844, &H4865, &H7806, &H6827, _
 &H18c0, &H8e1, &H3882, &H28a3, &Hcb7d, &Hdb5c, _
 &Heb3f, &Hfb1e, &H8bf9, &H9bd8, &Habbb, &Hbb9a, _
 &H4a75, &H5a54, &H6a37, &H7a16, &Haf1, &H1ad0, _
 &H2ab3, &H3a92, &Hfd2e, &Hed0f, &Hdd6c, &Hcd4d, _
 &Hbdaa, &Had8b, &H9de8, &H8dc9, &H7c26, &H6c07, _
 &H5c64, &H4c45, &H3ca2, &H2c83, &H1ce0, &Hcc1, _
 &Hef1f, &Hff3e, &Hcf5d, &Hdf7c, &Haf9b, &Hbfba, _
 &H8fd9, &H9ff8, &H6e17, &H7e36, &H4e55, &H5e74, _
 &H2e93, &H3eb2, &Hed1, &H1ef0}

Public Function CRC16(dat As [Byte](), count As Integer) As Integer
 Dim crc As Integer = 0
 Dim crctemp As [Byte]
 Dim i As Integer = 0
 While count > 0
  count -= 1
  crctemp = Convert.ToByte(crc >> 8)
  crc = (crc << 8) And &Hffff
  crc = (CRC16Table(crctemp Xor dat(i)) Xor crc) And &Hffff
  i += 1
 End While
 Return crc
End Function

 

 

调用代码

 

Dim aaff As [Byte]() = {&H01, &H04, &H00, &H00, &H00, &H0a}
Dim aa As Integer = CRC16(aaff, aaff.Length)
Dim bb As String = Convert.ToString(aa, 16).ToUpper()
msgbox(bb)


 回到顶部
帅哥哟,离线,有人找我吗?
111yangguojun
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:243 积分:1928 威望:0 精华:0 注册:2013/8/8 23:49:00
  发帖心情 Post By:2014/12/23 10:52:00 [只看该作者]

感谢 甜老师 的热心帮助,这个方法我尝试过了,应该能解决问题,就是计算结果与我现在的可能有些偏差。

 

数据:01 04 00 00 00 0a 校验码:70 0d

这个例子的验证码是70 0d ,70是低位、0d是高位,用 甜老师的方法计算出来有一点出入   结果是 EC 6D,EC低位、6D高位。

 

帮忙看下要修改哪个地方可以达到与我现在的校验一致。下面再附一些校验的例子。

 

数据:01 04 00 00 00 0a      校验码(前面低位、后面高位):70 0d

数据:22 04 00 00 00 08      校验码(前面低位、后面高位):f6 9f

数据:01 04 00 14 00 02      校验码(前面低位、后面高位):31 cf

数据:02 04 00 00 00 0a      校验码(前面低位、后面高位):70 3e

数据:01 04 00 14 00 0a      校验码(前面低位、后面高位):30 09

 

数据:01 04 14 00 01 67 08 00 00 00 00 00 00 15 00 00 00 00 00 00 00 80 0C    校验码(前面低位、后面高位):F0 94

数据:01 04 14 00 01 0D 08 6B 02 FE 04 63 00 16 00 00 00 00 00 00 00 80 0C    校验码(前面低位、后面高位):A5 7F

数据:01 04 14 00 01 0E 08 6B 02 FE 04 63 00 19 00 00 00 00 00 00 00 80 0C    校验码(前面低位、后面高位):65 0B

数据:01 04 14 00 01 0E 08 6C 02 FD 04 63 00 1B 00 00 00 00 01 93 01 80 0C    校验码(前面低位、后面高位):C4 B4

数据:01 04 14 00 01 0B 08 6B 02 03 FB 9D FF 1E 00 00 00 FD 00 84 01 80 0C    校验码(前面低位、后面高位):99 C3

 

上面的数据我用其他的CRC16校验码计算器  计算的结果是一致的。


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/12/23 11:13:00 [只看该作者]

 无法帮你测试,你的结果是错的。请贴出运算规则,你的肯定不是CRC16的标准计算。

 回到顶部
帅哥哟,离线,有人找我吗?
111yangguojun
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:243 积分:1928 威望:0 精华:0 注册:2013/8/8 23:49:00
  发帖心情 Post By:2014/12/23 17:37:00 [只看该作者]

CRC16 计算方法【查表法】:使用2 个256 长度的校验表
// --------------------------------------------------------------
// CRC 高位字节值表
//---------------------------------------------------------------
const BYTE chCRCHTalbe[] =
{
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40
};
// --------------------------------------------------------------
// CRC 低位字节值表
//---------------------------------------------------------------
const BYTE chCRCLTalbe[] =
{
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7,
0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E,
0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9,
0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC,
0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32,
0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D,
0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38,
0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF,
0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1,
0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4,
0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB,
0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA,
0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0,
0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97,
0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E,
0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89,
0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83,
0x41, 0x81, 0x80, 0x40
};
// --------------------------------------------------------------
// CRC 算法子函数
//---------------------------------------------------------------
WORD CRC16_1(BYTE* pchMsg, WORD wDataLen)
{
BYTE chCRCHi = 0xFF; // 高CRC 字节初始化
BYTE chCRCLo = 0xFF; // 低CRC 字节初始化
WORD wIndex; // CRC 循环中的索引
while (wDataLen--)
{
// 计算CRC
wIndex = chCRCLo ^ *pchMsg++ ;
chCRCLo = chCRCHi ^ chCRCHTalbe[wIndex];
chCRCHi = chCRCLTalbe[wIndex] ;
}
return ((chCRCHi << 8) | chCRCLo) ;
}

 

这个是  上面数据与校验码的算法,不清楚如何转换成狐表的代码,看着都眼花缭乱的


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/12/23 18:03:00 [只看该作者]

 全局代码

 

Public chCRCHTalbe As UInteger() = {&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H0, &Hc1, &H81, &H40, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H0, &Hc1, _
&H81, &H40, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H0, &Hc1, &H81, &H40, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H0, &Hc1, &H81, &H40, _
&H1, &Hc0, &H80, &H41, &H1, &Hc0, _
&H80, &H41, &H0, &Hc1, &H81, &H40, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H0, &Hc1, &H81, &H40, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H0, &Hc1, _
&H81, &H40, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H0, &Hc1, _
&H81, &H40, &H1, &Hc0, &H80, &H41, _
&H1, &Hc0, &H80, &H41, &H0, &Hc1, _
&H81, &H40, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H0, &Hc1, _
&H81, &H40, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H0, &Hc1, &H81, &H40, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H0, &Hc1, _
&H81, &H40, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40, &H1, &Hc0, _
&H80, &H41, &H1, &Hc0, &H80, &H41, _
&H0, &Hc1, &H81, &H40}

Public chCRCLTalbe As Uinteger() = {&H0, &Hc0, &Hc1, &H1, &Hc3, &H3, _
&H2, &Hc2, &Hc6, &H6, &H7, &Hc7, _
&H5, &Hc5, &Hc4, &H4, &Hcc, &Hc, _
&Hd, &Hcd, &Hf, &Hcf, &Hce, &He, _
&Ha, &Hca, &Hcb, &Hb, &Hc9, &H9, _
&H8, &Hc8, &Hd8, &H18, &H19, &Hd9, _
&H1b, &Hdb, &Hda, &H1a, &H1e, &Hde, _
&Hdf, &H1f, &Hdd, &H1d, &H1c, &Hdc, _
&H14, &Hd4, &Hd5, &H15, &Hd7, &H17, _
&H16, &Hd6, &Hd2, &H12, &H13, &Hd3, _
&H11, &Hd1, &Hd0, &H10, &Hf0, &H30, _
&H31, &Hf1, &H33, &Hf3, &Hf2, &H32, _
&H36, &Hf6, &Hf7, &H37, &Hf5, &H35, _
&H34, &Hf4, &H3c, &Hfc, &Hfd, &H3d, _
&Hff, &H3f, &H3e, &Hfe, &Hfa, &H3a, _
&H3b, &Hfb, &H39, &Hf9, &Hf8, &H38, _
&H28, &He8, &He9, &H29, &Heb, &H2b, _
&H2a, &Hea, &Hee, &H2e, &H2f, &Hef, _
&H2d, &Hed, &Hec, &H2c, &He4, &H24, _
&H25, &He5, &H27, &He7, &He6, &H26, _
&H22, &He2, &He3, &H23, &He1, &H21, _
&H20, &He0, &Ha0, &H60, &H61, &Ha1, _
&H63, &Ha3, &Ha2, &H62, &H66, &Ha6, _
&Ha7, &H67, &Ha5, &H65, &H64, &Ha4, _
&H6c, &Hac, &Had, &H6d, &Haf, &H6f, _
&H6e, &Hae, &Haa, &H6a, &H6b, &Hab, _
&H69, &Ha9, &Ha8, &H68, &H78, &Hb8, _
&Hb9, &H79, &Hbb, &H7b, &H7a, &Hba, _
&Hbe, &H7e, &H7f, &Hbf, &H7d, &Hbd, _
&Hbc, &H7c, &Hb4, &H74, &H75, &Hb5, _
&H77, &Hb7, &Hb6, &H76, &H72, &Hb2, _
&Hb3, &H73, &Hb1, &H71, &H70, &Hb0, _
&H50, &H90, &H91, &H51, &H93, &H53, _
&H52, &H92, &H96, &H56, &H57, &H97, _
&H55, &H95, &H94, &H54, &H9c, &H5c, _
&H5d, &H9d, &H5f, &H9f, &H9e, &H5e, _
&H5a, &H9a, &H9b, &H5b, &H99, &H59, _
&H58, &H98, &H88, &H48, &H49, &H89, _
&H4b, &H8b, &H8a, &H4a, &H4e, &H8e, _
&H8f, &H4f, &H8d, &H4d, &H4c, &H8c, _
&H44, &H84, &H85, &H45, &H87, &H47, _
&H46, &H86, &H82, &H42, &H43, &H83, _
&H41, &H81, &H80, &H40}

Public Function CRC16(pchMsg As uinteger(), wDataLen As ushort) As ushort
Dim chCRCHi As uinteger = &Hff
' 高CRC 字节初始化
Dim chCRCLo As uinteger = &Hff
' 低CRC 字节初始化
Dim wIndex As ushort
Dim i As ushort = 0
' CRC 循环中的索引
While wDataLen > 0
    ' 计算CRC
    wIndex = chCRCLo Xor pchMsg(i)
    i += 1
    chCRCLo = chCRCHi Xor chCRCHTalbe(wIndex)
    chCRCHi = chCRCLTalbe(wIndex)
    wDataLen -= 1
End While
Return ((chCRCHi << 8) Or chCRCLo)

End Function

[此贴子已经被作者于2018/11/16 10:43:10编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/12/23 18:04:00 [只看该作者]

调用

 

Dim aaff As uInteger() = {&H01, &H03, &H04, &H01, &Hf4, &H13, &H88}
Dim aa As Integer = CRC16(aaff, aaff.Length)
Dim bb As String = Convert.ToString(aa, 16).ToUpper()
msgbox(bb)

[此贴子已经被作者于2018/11/16 10:46:13编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
111yangguojun
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:243 积分:1928 威望:0 精华:0 注册:2013/8/8 23:49:00
  发帖心情 Post By:2014/12/24 10:55:00 [只看该作者]

新代码测试后,出现的结果已经很接近了,稍微有一点点问题,

 

数据:01 04 00 00 00 0a      校验码 :70 0d的时候,我们新代码出来的是  最前一位和最后一位 7d

数据:22 04 00 00 00 08      校验码  : f6 9f 的时候,我们新代码出来的是  最前一位和最后一位 ff

其他的数据也测试过,都符合这个,  缺少了  中间2个数。

 

 

数据:01 04 00 00 00 0a      校验码(前面低位、后面高位):70 0d

数据:22 04 00 00 00 08      校验码(前面低位、后面高位):f6 9f

数据:01 04 00 14 00 02      校验码(前面低位、后面高位):31 cf

数据:02 04 00 00 00 0a      校验码(前面低位、后面高位):70 3e

数据:01 04 00 14 00 0a      校验码(前面低位、后面高位):30 09


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/12/24 10:56:00 [只看该作者]

 你给的算法有问题。

 回到顶部
总数 15 1 2 下一页