ccitt crc16 algoritham
the polynomial for this algorithm is X**16+X**12+X**5+1
D = current data byte that is input to the algorithm
CRCLSB,CRCMSB=data byte.least significant and most significant CRC accumulator
bytes
x>>n means x is shifted n bits to right or is the same as x divided by 2 to the power n
x<<n means x is shifted n bits to left or is the same as x multiplied by 2 to the power n
======================algoritham=======================================
at beginning,
CRCLSB = 0FFH(octal 377)(decimal 255)
CRCMSB = 0FFH(octal 377)(decimal 255)
then for each data byte in a block,
X=D XOR CRCMSB
x=x xor (X>>4)
CRCMSB=CRCLSB XOR(X>>3)XOR(X<<4)
CRCLSB=X XOR(X<<5)
and at end,
CRCLSB=CRCLSB XOR 0FFH
CRCMSB=CRCMSB XOR 0FFH
======================this is vb6 program for above algoritham=======================================
Public Function CRC16A(Buffer() As Byte) As Long
Dim i As Long
Dim Temp As Long
Dim crc As Long
Dim j As Integer
crc = &HFFFF&
For i = LBound(Buffer) To UBound(Buffer)
Temp = Buffer(i) * &H100&
crc = crc Xor Temp
For j = 0 To 255
If (crc And &H8000&) Then
crc = ((crc * 2) Xor &H1021&) And &HFFFF&
Else
crc = (crc * 2) And &HFFFF&
End If
Next j
Next i
CRC16A = crc And &HFFFF
End Function
Private Sub Command1_Click()
Dim aBuf() As Byte
Dim crc As Long
Dim p As String
p = Text1.Text
aBuf = StrConv(p, vbFromUnicode)
crc = CRC16A(aBuf)
Text2.Text = Hex(crc)
End Sub
===============could you help to get correct answer=====
the polynomial for this algorithm is X**16+X**12+X**5+1
D = current data byte that is input to the algorithm
CRCLSB,CRCMSB=data byte.least significant and most significant CRC accumulator
bytes
x>>n means x is shifted n bits to right or is the same as x divided by 2 to the power n
x<<n means x is shifted n bits to left or is the same as x multiplied by 2 to the power n
======================algoritham=======================================
at beginning,
CRCLSB = 0FFH(octal 377)(decimal 255)
CRCMSB = 0FFH(octal 377)(decimal 255)
then for each data byte in a block,
X=D XOR CRCMSB
x=x xor (X>>4)
CRCMSB=CRCLSB XOR(X>>3)XOR(X<<4)
CRCLSB=X XOR(X<<5)
and at end,
CRCLSB=CRCLSB XOR 0FFH
CRCMSB=CRCMSB XOR 0FFH
======================this is vb6 program for above algoritham=======================================
Public Function CRC16A(Buffer() As Byte) As Long
Dim i As Long
Dim Temp As Long
Dim crc As Long
Dim j As Integer
crc = &HFFFF&
For i = LBound(Buffer) To UBound(Buffer)
Temp = Buffer(i) * &H100&
crc = crc Xor Temp
For j = 0 To 255
If (crc And &H8000&) Then
crc = ((crc * 2) Xor &H1021&) And &HFFFF&
Else
crc = (crc * 2) And &HFFFF&
End If
Next j
Next i
CRC16A = crc And &HFFFF
End Function
Private Sub Command1_Click()
Dim aBuf() As Byte
Dim crc As Long
Dim p As String
p = Text1.Text
aBuf = StrConv(p, vbFromUnicode)
crc = CRC16A(aBuf)
Text2.Text = Hex(crc)
End Sub
===============could you help to get correct answer=====