Re: CRC-16 and CRC-32

 BBS: Inland Empire Archive
Date: 02-11-93 (18:10)             Number: 361
From: DICK DENNISON                Refer#: NONE
  To: VICTOR YIU                    Recvd: NO  
Subj: Re: CRC-16 and CRC-32          Conf: (2) Quik_Bas
VY>     Can anyone tell me how to modify Rich's QBCRC10 CRC-32 maker to ma
VY> 16-bit CRCs?  I already have the CRC-32 code, so reposting it is unnec
VY> Thanks!
  'From Donn Bly:

DECLARE FUNCTION Computecrc& (x$)
'OPEN "ccit.bas" FOR OUTPUT AS 1
CLS
FOR x = 0 TO 255
    crc& = Computecrc&(CHR$(x))
    PRINT HEX$(crc&),
NEXT

FUNCTION Computecrc& (x$)
' ComputeCRC - Copyright (C) 1989, Donn Bly, 1:236/7.0
'
' Standard Donn Bly Licencing Agreement:
'  This code may be used for anything that you want, except for profit.  I
f
'  you want to profit from my work you had better talk to me first.
'  NOTE: The CRC Polynomial was redone by Dick Dennison for CCIT16
STATIC InputByte AS INTEGER, CRCword AS LONG, c%, FeedBackBit AS INTEGER
'
' CRC Calculation Polynomial = X^16+X^12+X^5+X^0     (CCIT 16)
'
' X$ is the block on which to compute the CRC
'
CRCword = 0  'this line is Dick's
FOR c% = 1 TO LEN(x$)
   InputByte = ASC(MID$(x$, c%, 1))
   FeedBackBit = ((CRCword AND 32768) = 32768) XOR ((InputByte AND 128) =
128)
   CRCword = ((CRCword AND 32767&) * 2&)
   IF FeedBackBit THEN CRCword = CRCword XOR &H1021&
   FeedBackBit = ((CRCword AND 32768) = 32768) XOR ((InputByte AND 64) = 6
4)
   CRCword = ((CRCword AND 32767&) * 2&)
   IF FeedBackBit THEN CRCword = CRCword XOR &H1021&
   FeedBackBit = ((CRCword AND 32768) = 32768) XOR ((InputByte AND 32) = 3
2)
   CRCword = ((CRCword AND 32767&) * 2&)
   IF FeedBackBit THEN CRCword = CRCword XOR &H1021&
   FeedBackBit = ((CRCword AND 32768) = 32768) XOR ((InputByte AND 16) = 1
6)
   CRCword = ((CRCword AND 32767&) * 2&)
   IF FeedBackBit THEN CRCword = CRCword XOR &H1021&
   FeedBackBit = ((CRCword AND 32768) = 32768) XOR ((InputByte AND 8) = 8)
   CRCword = ((CRCword AND 32767&) * 2&)
   IF FeedBackBit THEN CRCword = CRCword XOR &H1021&
   FeedBackBit = ((CRCword AND 32768) = 32768) XOR ((InputByte AND 4) = 4)
   CRCword = ((CRCword AND 32767&) * 2&)
   IF FeedBackBit THEN CRCword = CRCword XOR &H1021&
   FeedBackBit = ((CRCword AND 32768) = 32768) XOR ((InputByte AND 2) = 2)
   CRCword = ((CRCword AND 32767&) * 2&)
   IF FeedBackBit THEN CRCword = CRCword XOR &H1021&
   FeedBackBit = ((CRCword AND 32768) = 32768) XOR ((InputByte AND 1) = 1)
   CRCword = ((CRCword AND 32767&) * 2&)
   IF FeedBackBit THEN CRCword = CRCword XOR &H1021&
NEXT c%
Computecrc& = CRCword&
END FUNCTION
 'Sorry about the wrap.  This is for CCIT16 (the xmodem type).

--- VP [DOS] V4.09e
 * Origin: The MailMan  (914)374-3903 NY Quick Share Pt #7 *HST (1:272/34)
Outer Court
Echo Basic Postings

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