当前位置:首页 » 操作系统 » 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

热点内容
如何在设置看见自己修改的密码 发布:2024-10-30 09:25:29 浏览:808
v8引擎可以编译js 发布:2024-10-30 09:24:43 浏览:277
智能锁默认管理员密码是多少位 发布:2024-10-30 09:23:53 浏览:927
oss图片压缩 发布:2024-10-30 09:07:58 浏览:85
从哪里看安卓编译脚本变量定义 发布:2024-10-30 08:58:53 浏览:56
压缩器波形 发布:2024-10-30 08:58:11 浏览:307
哪个三维软件要求电脑配置比较低 发布:2024-10-30 08:50:56 浏览:1000
防爆系统的wifi密码是多少 发布:2024-10-30 08:47:25 浏览:285
安卓日语输入法怎么用 发布:2024-10-30 08:44:09 浏览:111
sqlserver的len 发布:2024-10-30 08:41:24 浏览:850