=========================================================================== BBS: The Abacus * HST/DS * Potterville MI Date: 03-06-93 (23:46) Number: 62 From: CORIDON HENSHAW Refer#: 155 To: CABELL CLARKE Recvd: NO Subj: CRC Conf: (35) Quick Basi --------------------------------------------------------------------------- Hello Cabell! Friday March 05 1993, Cabell Clarke writes to All: CC> Does anyone have or know of a routine to compute a crc 32 from a string? I CC> am in dire need of such as beast and would kill to get my hands on one. Here's some BASIC source for CRC32 and CRC26. I also have a ASM version of the CRC32 code, if you want it. === BEGIN === DECLARE FUNCTION CRC16& (Block$) DECLARE FUNCTION CRC32& (Block$) DEFINT A-Z FUNCTION CRC16& (B$) 'Calculates CRC for Each Block DIM Power(0 TO 7) 'For the 8 Powers of 2 DIM CRC AS LONG FOR I = 0 TO 7 'Calculate Once Per Block to Power(I) = 2 ^ I ' Increase Speed Within FOR J NEXT I ' Loop CRC = 0 'Reset for Each Text Block FOR I = 1 TO LEN(B$) 'Calculate for Length of Block ByteVal = ASC(MID$(B$, I, 1)) FOR J = 7 TO 0 STEP -1 TestBit = ((CRC AND 32768) = 32768) XOR ((ByteVal AND Power(J)) = _ Power( J)) CRC = ((CRC AND 32767&) * 2&) IF TestBit THEN CRC = CRC XOR &H1021& ' <-- This for 16 Bit CRC NEXT J NEXT I CRC16& = CRC 'Return the Word Value END FUNCTION DEFSNG A-Z FUNCTION CRC32& (B$) 'Calculates CRC for Each Block DIM Power(0 TO 7) 'For the 8 Powers of 2 DIM CRC AS LONG FOR I = 0 TO 7 'Calculate Once Per Block to Power(I) = 2 ^ I ' Increase Speed Within FOR J NEXT I ' Loop CRC = 0 'Reset for Each Text Block FOR I = 1 TO LEN(B$) 'Calculate for Length of Block ByteVal = ASC(MID$(B$, I, 1)) FOR J = 7 TO 0 STEP -1 TestBit = ((CRC AND 32768) = 32768) XOR ((ByteVal AND Power(J)) =_ Power(J )) CRC = ((CRC AND 32767&) * 2&) IF TestBit THEN CRC = CRC XOR &H8005& ' <-- This for 32 Bit CRC NEXT J NEXT I CRC32& = CRC 'Return the Word Value END FUNCTION === END === Coridon Henshaw / Sirrus Software / QBCIMR FTSC Standards Technician / SM DEV --- GEcho 1.00 * Origin: TCS Concordia - Mail Only - Toronto, Ontario (1:250/820) SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1 SEEN-BY: 153/752 154/40 77 157/2 159/100 125 430 950 203/23 209/209 280/1 SEEN-BY: 390/1 396/1 15 397/2 2230/100 3603/20