当前位置:首页 » 操作系统 » crc校验源码

crc校验源码

发布时间: 2022-06-03 07:13:50

⑴ 【人民币酬谢】求易语言crc16校验和代码

网上查呀

⑵ crc16校验的c语言程序

unsigned short crc_dsp(unsigned short reg, unsigned char data_crc)
//reg为crc寄存器, data_crc为将要处理的8bit数据流
{
unsigned short msb; //crc寄存器将移出的最高1bit
unsigned short data;
unsigned short gx = 0x8005, i = 0; //i为左移次数, gx为生成多项式

data = (unsigned short)data_crc;
data = data << 8;
reg = reg ^ data;
do
{
msb = reg & 0x8000;
reg = reg << 1;
if(msb == 0x8000)
{
reg = reg ^ gx;
}
i++;
}
while(i < 8);
return (reg);
}

⑶ 计算CRC校验码问题

首先 G(X)=X3+X+1 可以得出 G(x) = 1011 [G(x)中的 1 就是二进制第0位为1,X就是第一位为1,没有X^2,所以第二位为0,X^3则第三位为1.所以就是1011]
M(x) = 0011 M(x)*x3 = 0011000
M(x)*x3 / G(x)的余数是 101 所以 R(X)=101
CRC码为: M(x)*x 3+R(x)=0011000+010 =0011010

⑷ vb,crc校验的程序

'Text1.Text 输入数据
'Text2.Text 输出数据
Dim ReturnData(1) As Byte
Private Sub Command1_Click()
Dim CRC(2) As Byte
Dim d(6) As Byte '待传输数据
ReDim data(7) As Byte
For i = 0 To 5
data(i) = "&h" + Mid(Text1.Text, 2 * i + 1, 2)
Debug.Print data(i)
Next i
Call CRC16(data, UBound(data) - 2, data(6), data(7)) '调用CRC16计算函数
' CRC(0)为高位
' CRC(1)为低位
End Sub
Function CRC16(data() As Byte, i As Integer, ByRef ReturnDatalo As Byte, ByRef ReturnDatahi As Byte) As String
Dim CRC16Lo As Byte, CRC16Hi As Byte 'CRC寄存器
Dim CL As Byte, CH As Byte '多项式码&HA001
Dim SaveHi As Byte, SaveLo As Byte
Dim Flag As Integer

CRC16Lo = &HFF
CRC16Hi = &HFF
CL = &H1
CH = &HA0

For i = 0 To UBound(data) - 2
CRC16Lo = CRC16Lo Xor data(i) '每一个数据与CRC寄存器进行异或
For Flag = 0 To 9
SaveHi = CRC16Hi
SaveLo = CRC16Lo
CRC16Hi = CRC16Hi \ 2 '高位右移一位
CRC16Lo = CRC16Lo \ 2 '低位右移一位
If ((SaveHi And &H1) = &H1) Then '如果高位字节最后一位为1
CRC16Lo = CRC16Lo Or &H80 '则低位字节右移后前面补1
End If '否则自动补0
If ((SaveLo And &H1) = &H1) Then '如果LSB为1,则与多项式码进行异或
CRC16Hi = CRC16Hi Xor CH
CRC16Lo = CRC16Lo Xor CL
End If
Next Flag
Next i

ReturnDatahi = CRC16Hi 'CRC高位
ReturnDatalo = CRC16Lo 'CRC低位

Debug.Print Hex(CRC16Lo), Hex(CRC16Hi)

Text2.Text = Text1.Text & Hex(CRC16Lo) & Hex(CRC16Hi)

End Function

⑸ 谁有VB CRC16校验源码

Public Function UnsignInt(ByRef Num As Variant) As Boolean
Num = Num And &HFFFF&
End Function

'8005
Public Function CRC168005(ptr() As Byte) As String
Dim i As Integer, J As Integer
Dim Index As Integer
Dim crc As Long

crc = 0
Index = 0

For J = 0 To UBound(ptr)
i = &H80
Do While (i > 0)
UnsignInt crc

If ((crc And &H8000&) <> 0) Then

crc = crc * 2

UnsignInt crc
crc = crc Xor &H8005&

Else
crc = crc * 2
'crc = UnsignedAdd(crc, crc)

End If

If ((ptr(Index) And i) <> 0) Then
UnsignInt crc
crc = crc Xor &H8005& '关键点 结尾&符号
End If

i = i / 2
Loop

Index = Index + 1

Next

CRC168005 = Hex(crc)

End Function

'A001
Public Function CRC16(data() As Byte) As String
Dim CRC16Lo As Byte, CRC16Hi As Byte 'CRC寄存器
Dim CL As Byte, CH As Byte '多项式码&HA001
Dim SaveHi As Byte, SaveLo As Byte
Dim i As Integer
Dim flag As Integer
CRC16Lo = &HFF
CRC16Hi = &HFF
CL = &H1
CH = &HA0
For i = 0 To UBound(data)
CRC16Lo = CRC16Lo Xor data(i) '每一个数据与CRC寄存器进行异或
For flag = 0 To 7
SaveHi = CRC16Hi
SaveLo = CRC16Lo
CRC16Hi = CRC16Hi \ 2 '高位右移一位
CRC16Lo = CRC16Lo \ 2 '低位右移一位
If ((SaveHi And &H1) = &H1) Then 'VB下的CRC校验程序高位字节最后一位为1
CRC16Lo = CRC16Lo Or &H80 '则低位字节右移后前面补1
End If '否则自动补0
If ((SaveLo And &H1) = &H1) Then 'VB下的CRC校验程序LSB为1,则与多项式码进行异或
CRC16Hi = CRC16Hi Xor CH
CRC16Lo = CRC16Lo Xor CL
End If
Next flag
Next i
Dim ReturnData(2) As Byte
ReturnData(0) = CRC16Hi 'CRC高位
ReturnData(1) = CRC16Lo 'CRC低位
CRC16 = Bit(Hex(ReturnData(0))) & Bit(Hex(ReturnData(1)))
End Function

热点内容
win7vhd加密 发布:2025-01-10 18:20:35 浏览:419
手机存储空间里的其他怎么清理 发布:2025-01-10 18:19:59 浏览:800
二手的电脑服务器都怎么处理了 发布:2025-01-10 18:19:05 浏览:905
定压补水装置如何配置 发布:2025-01-10 18:12:34 浏览:429
安卓是华为的什么 发布:2025-01-10 18:12:27 浏览:539
pythonsetget 发布:2025-01-10 17:53:12 浏览:853
买脚本多少钱 发布:2025-01-10 17:52:34 浏览:934
文件夹万能解密器破解版 发布:2025-01-10 17:48:12 浏览:463
荣耀v30跟荣耀50哪个配置高 发布:2025-01-10 17:43:00 浏览:239
php发布系统 发布:2025-01-10 17:34:17 浏览:367