Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to calculate usual CRC16 if VFP
Message
 
 
To
14/10/2005 14:53:27
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01059252
Message ID:
01059378
Views:
15
The code below seems to produce correct result but it hasn't been tested thoroughly.
* http://www.summitinstruments.com/library/tn410.htm
* http://www.lammertbies.nl/comm/info/crc-calculation.html?crc=1234567898765421&method=ascii
*** Polynom = 0x8005
#DEFINE CRC16 0xA001

* Build CRC table
DIMENSION laCrc[256]

FOR i=0 TO 255

	lnData = i
	lnCrc = 0
	FOR j=0 TO 7
		IF BITAND(BITXOR(lnData, lnCrc),1) > 0
			lnCrc = BITXOR(BITRSHIFT(lnCrc,1), CRC16)
		ELSE
			lnCrc = BITRSHIFT(lnCrc,1)
		ENDIF

		lnData = BITRSHIFT(lnData,1)
		
	ENDFOR
	
	*? i, TRANSFORM(lnCrc, "@0")
	laCrc[i+1] = lnCrc
ENDFOR

* Calculate CRC16
***Str = "123456789"
lcStr = "1234567898765421"

lnCrc = 0
FOR i=1 TO LEN(lcStr)
	lnByte = ASC(SUBSTR(lcStr,i,1))
	lnCrc = BITXOR( BITRSHIFT(lnCrc,8), ;
				laCrc[BITXOR(BITAND(lnCrc, 0xFF), lnByte)+1])
ENDFOR
? TRANSFORM(lnCrc, "@0")
BTW, neither one of CRC16 algorithms is more "usual" than another.

>I need to calculate usual CRC16 (polynom 0x8005) in VFP.
>
>VFP SYS(2007) and Bob Herguth source code in
>http://fox.wikis.com/wc.dll?Wiki~CRC16~SoftwareEng will calculate only
>CRC-CCITT (polynom 0x1021) checksum.
>
>Any idea how to calculate "usual" CRC16 ?
>
>Is it possible to modify Bob Herguth source code or use some other function ?
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform