- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
很遗憾,我不得不承认我放弃了用 VBA 编程语言搜索正确的 CRC8 代码的 8 小时。有很多例子,但我还没有找到适合我的例子。所以我在这里,向您寻求帮助,是否有人可以将这部分代码写给我,或者是否有一个我没有点击过的神秘链接。
解释:
AppID = "A00000039656434103F0154020D4000A"
在我的项目中,要求字符“A”位于此 AppID 的末尾,因为应基于此计算 CRC8。如果理解正确(因为我可能一整天都在尝试编写此 CRC8 函数而发疯)我有 32-byte
ID,我想在 16bits 上对其进行 CRC8 检查
(这有意义吗?)
在给定的示例中,我只有 CRC8 应该返回的结果:
CRC8 = 0x6D
我需要用我的主 AppID 中的字符“A”替换下半部分:
FinalAppID = "A00000039656434103F0154020D4000D"
问题:但我根本不知道如何编写或转换 C++/C# 代码。我真的被逐步转换所困扰,但它没有用。
这是我使用的代码:
Public function calculateCRC8(ByVal AppID As String ) As String
Dim CRC8 As Byte
Dim i as Integer
Dim j as Integer
Dim AppIDarray()
CRC8 = &HC7; //Based on preset 0xE3
aidLenght = LEN(AppID)
AppIDarray = StringToArray(AppID) ' I user a UDF that I wrote, this should work OK'
For j = 0 To aidLenght
CRC8 = CRC8 Xor AppIDarray(j)
For i = 1 To 8
If CRC8 And &H80 Then
CRC8 = (CRC8 * 2) Xor &H1D
Else
CRC8 = CRC8 * 2
End If
next i
Next j
calculateCRC8 = CRC8
End Function
以上代码出现的问题是:
错误:
Error: Overflow!
即使我传递了整个字符串
,或者只是16bits
,也会出现这个错误。同样的错误。
如果有人有什么可以帮助我的,我将非常感谢他!
最佳答案
这是一个带有一些修复的版本,它可以防止溢出的发生。它为您的十六进制字节 (A00000039656434103F0154020D4000A) 生成预期结果 (&H6D)。
Public Function calculateCRC8(ByVal AppID As String) As String
Dim CRC8 As Byte
Dim i As Integer
Dim j As Integer
Dim AppIDarray() As Byte '<--- explicitly dimensioned as a Byte array to avoid confusion
CRC8 = &HC7
'The AppID is actually bytes stored in hexadecimal in a string. You have to convert them back to bytes before you can run a crc8 on them.
AppIDarray = HexToByte(AppID)
aidLength = UBound(AppIDarray)
For j = 0 To aidLength
CRC8 = CRC8 Xor AppIDarray(j)
For i = 1 To 8
If CRC8 And &H80 Then
'masking off the left-most bit before shifting prevents the Overflow error.
CRC8 = ((&H7F And CRC8) * 2) Xor &H1D
Else
CRC8 = CRC8 * 2
End If
Next i
Next j
calculateCRC8 = CRC8
End Function
此函数接受十六进制字符串并将其解释为 Byte
数组。
Public Function HexToByte(strHex As String) As Byte()
Dim i As Integer
Dim tempByte As Byte
Dim outBytes() As Byte
ReDim outBytes(Len(strHex) \ 2 - 1)
For i = 0 To Len(strHex) \ 2 - 1
For j = 0 To 1
char = Mid(strHex, i * 2 + j + 1, 1)
Select Case char
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
tempByte = tempByte Or (Asc(char) - 48)
Case "A", "B", "C", "D", "E", "F":
tempByte = tempByte Or (Asc(char) - 55)
End Select
If j = 0 Then
tempByte = tempByte * 2 ^ 4
Else
outBytes(i) = tempByte
tempByte = 0
End If
Next
Next
HexToByte = outBytes
End Function
关于ms-access - 在 VBA 中计算 CRC8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26664204/
我已经搜索过,但无法找到有关它是什么以及如何计算的信息。 我不知道为什么这个问题被否决了。不是说清楚和编程有关吗?或者我应该问: # Or you can compute the running CR
如果我有一定数量的字节要串行传输,我如何确定使用哪个 CRC(CRC8、CRC16 等,基本上是多少位的 CRC?)并且错误检测百分比仍然很高?有这个公式吗? 最佳答案 从 CRC 长度的角度来看,适
这个问题在这里已经有了答案: Incremental Checksums (3 个答案) 关闭 8 年前。 如果我有子串 S0, S1, ... Sn 计算出的 CRCs C0, C1, ... C
我知道 CRC 是一个线性函数,这意味着 CRC(x xor y) = CRC(x) xor CRC(y),但我不知道如何证明 CRC 的这个属性。 有谁有想法吗? 非常感谢! 最佳答案 这通常不是真
我知道使用 CRC 的全部目的是进行错误检测,但我听说有人说除了错误检测之外,它还可以用来进行基本的错误纠正。我很好奇是否是这样,如果是这样,它有多强大?我的意思是,我们通常将 CRC 称为能够执行
我见过 8 位、16 位和 32 位 CRC。 在什么时候我需要跳转到更广泛的 CRC? 我的直觉 react 是它基于数据长度: 1-100 字节:8 位 CRC 101 - 1000 字节:16
我正在学习 CRC,搜索引擎和 SO 对此一无所知...... 为什么我们有“正态”、“逆向”和“倒数”多项式?是喜欢 Big Endian、Little Endian 还是其他什么? 最佳答案 CR
在学习计算机网络类(class)时,教授谈到了示例代码中两个有效代码字之间的汉明距离。我已经阅读了有关汉明距离的信息,从告诉 2 个字符串之间的差异距离的角度来看,这是有道理的。例如: Code Wo
我从Wikipedia知道CRC计算算法。关于RAR文件的结构我读过here 。例如有这样写: The file has the magic number of: 0x 52 61 72 21
我已经阅读了 CCITT 和 TI 关于 msp430 的文档。是否可以使用任何内置函数计算 MSP430F5438A 的 CRC?或者我是否必须为每个获取的数据计算 CRC。 最佳答案 可以使用软件
我尝试修改现有项目的 CRC 模块。目前它使用 CRC-16-CCITT。从代码中我知道它的多项式是0x11021,它的CRC-Table是: static const unsigned sh
使用线性反馈移位寄存器(LFSR)实现CRC生成有两种方法,如图所示。图中生成多项式的系数为100111,红色“+”圆圈为异或运算符。两者的初始化寄存器值都是 00000。 例如,如果输入数据比特流是
当数据长度不是4的倍数时,有没有办法通过表驱动的方式加快CRC校验过程?在我的问题中,有 226 位需要检查,并通过 CRC24Q 算法为此计算了 24 位校验和。 最佳答案 使用表格计算第一部分的c
我需要计算消息的 CRC 并将其放在该消息的开头,以便带有“前置”补丁字节的消息的最终 CRC 等于 0。我能够做到这在几篇文章的帮助下非常容易,但不适用于我的特定参数。问题是我必须使用给定的 CRC
我正在将一些从我自己的类中定义的对象保存到文件中。 (保存流数据)。 这一切都很好,但我希望能够在文件中存储该文件的 CRC 校验和。 然后,每当我的应用程序尝试打开文件时,它都可以读取内部存储的 C
我有一组受 16 位校验和保护的数据,需要更正。校验和位置是已知的,计算它们的确切区域以及用于计算它们的确切算法却未知。 16 位,最低有效位在前。我怀疑这是某种 16 位 CRC,但我无法找到实际计
我想使用Nucleo L053R8的crc计算单元计算3字节的CRC值。生成多项式如下:g(X)=x^24 + x^10 + x^9 + x^6 + x^4 + x^3 + x + 1 看来使用这个C
开始之前:我绝对是 JAVA 的初学者。我一直是一名 C++ 程序员。所以当我在这里做傻事时请告诉我! 我正在查询一个巨大的数据库并将该数据直接导出到一个 zip 文件中。我们在这里讨论的是 35GB
我有一些 C++ 代码,我正在将其移植到 C。当我在 C 代码中计算 CRC 时,出于某种原因,它返回错误的 CRC 值,而 C++ 代码运行良好。我是 C++ 的新手。我需要一些帮助来理解我在返回错
我有两个来源来计算看似相同的 crc 值。我不明白为什么“boost/crc.hpp”实现与“linux/lib/crc-ccitt.c”实现不同。 crc-ccitt.c boost 这是一个说明问
我是一名优秀的程序员,十分优秀!