BBS: Inland Empire Archive Date: 03-06-93 (23:46) Number: 359 From: CORIDON HENSHAW Refer#: NONE To: CABELL CLARKE Recvd: NO Subj: CRC Conf: (2) Quik_Bas
Hello Cabell!
Friday March 05 1993, Cabell Clarke writes to All:
CC> Does anyone have or know of a routine to compute a crc
CC> 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)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET