有沒有類似我所提供的VB代碼的CRC代碼,請提供一下,謝謝
Function CRC8(ByRef Data() As Byte, beg As Byte, zijie As Byte, ByRef YanzhengMa() As Byte, shi As Byte) As Boolean
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 Byte
Dim flag As Integer
CRC8 = False
CRC16Lo = &H0
CL = &H8C
For i = beg To beg + zijie - 1
CRC16Lo = CRC16Lo Xor Data(i) '每一個資料與CRC暫存器進行異或
For flag = 0 To 7
SaveLo = CRC16Lo
CRC16Lo = CRC16Lo \ 2 '低位右移一位
If ((SaveLo And &H1) = &H1) Then '如果LSB為1,則與多項式碼進行異或
CRC16Lo = CRC16Lo Xor CL
End If
Next flag
Next i
YanzhengMa(shi) = CRC16Lo
CRC8 = True
End Function
uj5u.com熱心網友回復:
看一下這個是不是你需要的 http://www.tansoo.cn/?tag=crcuj5u.com熱心網友回復:
unit unCRC16;interface
function CalCRC16(AData:array of Byte; AStart,AEnd:Integer): Word;
implementation
function CalCRC16(AData:array of Byte; AStart,AEnd:Integer): Word;
const
GENP = $A001;
var
crc:Word;
i:Integer;
tmp:Byte;
procedure CalOneByte(AByte:Byte);
var
j:Integer;
begin
crc:=crc xor AByte;
for j := 0 to 7 do
begin
tmp:=crc and 1;
crc:=crc shr 1;
crc:= crc and $7FFF;
if tmp = 1 then
crc:= crc xor GENP;
crc:=crc and $FFFF;
end;
end;
begin
crc:=$FFFF;
for i := AStart to AEnd do
CalOneByte(AData[i]);
Result:=crc;
end;
end.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/124535.html
標籤:語言基礎/算法/系統設計
