BBS: Inland Empire Archive Date: 09-14-92 (18:46) Number: 315 From: DICK DENNISON Refer#: NONE To: BOB EDWARDS Recvd: NO Subj: Re: How to do CRC's in QB Conf: (2) Quik_Bas

->How does the CRC alagorithm go, and how do I adapt this to QB to make ->CRC's there? BE> I'll second that request. This sound like a good topic to cover BE> along with (1) compression, (2) file transfer protocols Ok, you asked for it. This is a routine I use to make the new CRC16 (CCIT spec) for our local network. The crc16 routine is copyright Donn Bly, so be advised to read the fine print enclosed, although the algorhythm is PD. This routine has not been optimized, so I don't want to hear complaints.'DIX CRC computes CCIT CRC for small nodelists for pdq'Dick Dennison 1:272/34 74270,3636@compuserve.com'12/15/91 stuffs crc into nodelist'1/7/92 allow for leading zerosDECLAREFUNCTIONPDQTimer&DECLAREFUNCTIONComputecrc& (x$)'from Donn BlyDIMaASSTRING* 1IFCOMMAND$= ""THENLINEINPUTab$ELSEab$ =COMMAND$ENDIFspec$ = "nodelist." + ab$OPENspec$FORINPUTAS1'throw away first lineLINEINPUT#1, oneline$ begin% = SEEK(1) replace% = begin% - 7'where the CRC number is to go laterCLOSE1OPENspec$FORBINARYAS1'nodelist name with first lineSEEK1, begin% Lenfile& = LOF(1) - begin%FORn& = 1TOLenfile&'this could easily be optimizedGET1, , a$'with B$GETxcrc& = Computecrc&(a$)NEXTn&CLOSE1IFLEN(textcrc$) < 5THENtextcrc$ = STRING$(5 - LEN(textcrc$), "0") + tex tcrc$OPENspec$FORBINARYAS1SEEK1, replace%PUT1, , textcrc$CLOSE1FUNCTIONComputecrc& (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. If' you want to profit from my work you had better talk to me first.' NOTE: The CRC Polynomial was redone by Dick Dennison for CCIT16STATICInputByteASINTEGER, 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'sFORc% = 1TOLEN(x$) InputByte = ASC(MID$(x$, c%, 1)) FeedBackBit = ((CRCwordAND32768) = 32768)XOR((InputByte AND 128) = 128) CRCword = ((CRCwordAND32767&) * 2&)IFFeedBackBitTHENCRCword = CRCwordXOR&H1021& FeedBackBit = ((CRCwordAND32768) = 32768)XOR((InputByte AND 64) = 6 4) CRCword = ((CRCwordAND32767&) * 2&)IFFeedBackBitTHENCRCword = CRCwordXOR&H1021& FeedBackBit = ((CRCwordAND32768) = 32768)XOR((InputByte AND 32) = 3 2) CRCword = ((CRCwordAND32767&) * 2&)IFFeedBackBitTHENCRCword = CRCwordXOR&H1021& FeedBackBit = ((CRCwordAND32768) = 32768)XOR((InputByte AND 16) = 1 6) CRCword = ((CRCwordAND32767&) * 2&)IFFeedBackBitTHENCRCword = CRCwordXOR&H1021& FeedBackBit = ((CRCwordAND32768) = 32768)XOR((InputByte AND 8) = 8) CRCword = ((CRCwordAND32767&) * 2&)IFFeedBackBitTHENCRCword = CRCwordXOR&H1021& FeedBackBit = ((CRCwordAND32768) = 32768)XOR((InputByte AND 4) = 4) CRCword = ((CRCwordAND32767&) * 2&)IFFeedBackBitTHENCRCword = CRCwordXOR&H1021& FeedBackBit = ((CRCwordAND32768) = 32768)XOR((InputByte AND 2) = 2) CRCword = ((CRCwordAND32767&) * 2&)IFFeedBackBitTHENCRCword = CRCwordXOR&H1021& FeedBackBit = ((CRCwordAND32768) = 32768)XOR((InputByte AND 1) = 1) CRCword = ((CRCwordAND32767&) * 2&)IFFeedBackBitTHENCRCword = CRCwordXOR&H1021&NEXTc% Computecrc& = CRCword&ENDFUNCTION'Sorry for the line wrap. Also be advised that there are at least twocommon CRC16 polynomials and either will yeild a different CRC. For more info on CRC's, look up 'C Programmer's Guide to serial Comm.' by Joe Campbell, Sams & Co., ISBN 0-672-22584-0. Feel free to abuse/use. --- VP [DOS] V4.09e * Origin: The MailMan (914)374-3903 NY Quick Share Pt #7 *HST (1:272/34)

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