Zdravim všetkých, pod "C" mám napisanu funkciu pre vypočet 8-bit CRC (polynom- X^8 + X^5 + X^4 + X^0) takto: unsigned char CalcCRC(void) { unsigned char i,k,x,CRC = 0x00; unsigned int *SourceAdr; SourceAdr = U0_Buffer; for(i=0;i<7;i++) { x = *SourceAdr; for(k=0;k<8;k++) { if ((x^CRC)&1) CRC=((CRC^0x18)>>1)|0x80; else CRC = CRC>>1; x >>= 1; } SourceAdr++; } return(CRC); } a potrebujem to prepísať do VB. Skúšal som takto lenže Return mi nevracia rovnaku hodnotu ako v "C". Vie mi niekto poradiť ? Vďaka
Function CalcCRC(ByVal A As Byte, ByVal B As Byte, ByVal C As Byte, ByVal D As Byte, ByVal E As Byte, ByVal F As Byte, ByVal G As Byte)
Dim X As Byte
Dim CRC As Byte = &H0
Dim i As Integer = 0
Dim Buffer() As Byte = {A, B, C, D, E, F, G}
For Z = 1 To 7
X = Buffer(i)
For K = 1 To 8
If ((X Xor CRC) And 1) Then
CRC = ((CRC Xor &H18) >> 1) Or &H80
Else
CRC = CRC >> 1
End If
X >>= 1
Next
i += 1
Next
Return (CRC)
End Function
|