crc校驗源碼
⑴ 【人民幣酬謝】求易語言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