beautypg.com

Calculating the crc – Grass Valley XSwitch Feb 08 2006 User Manual

Page 37

background image

XSWITCH Installation and Operation Manual

37

Calculating the CRC

Calculating the CRC

Given

: The XSWITCH information for the fields:

and the basic program to calculate the CRC:

BASIC CRC PROGRAM VER. 2.0 USING VISUAL BASIC 3.0

Static P(200) As integer

ICRC = 0

POLY = &H8408

Dstring$ = Input_Text$ This is the input string.

D = 0

i = 1

P(0) = 0
For J = 1 To Len (Dstring$)

c$ = Mid$(Dstring$,J,1)

Casc = Asc (c$) ‘Finds decimal value contained in ch-
arcter’s ASCII value.

D = D * 16 + Casc ‘Hex value calculated.

P(0) = P(0) + 1

P(i) = D

i = i + 1

D = 0

Next J
‘After calculating input string’s characters to hex val-
ue,

CRC = ICRC Calculate the CRC.

i = 1 to P(0)

D = P(i)
For J = 1 To 8

XFLG = (CRC Xor D) And 1

CRC = Int(CRC/2) And &H7FFF

If XFLG Then CRC = CRC Xor POLY

D = Int (D / 2)

Next J

Next i

................CrCHexValue$ = Hex$(CRC) ‘This is EN-
TIRE CRC string
.

dummylength = Len(CrCHexValue$)

LSB = Val (“&H” + Right$(CrCHexValue$, 2)) ‘Convert
hex value to decimal value
.

MSB = 0

If dummylength = 3 Then MSB = Val(“&H” + Left$
(CrCHexValue$, 1))

If dummylength > 3 Then MSB = Val(“&H” + Mid$ (CrCHex-

DEST

SRC

LEN

C/C

DATA1

...

DATAn

CRCL

CRCH