Crc'S And Ecc'S

 BBS: Inland Empire Archive
Date: 03-24-92 (01:28)             Number: 145
From: JEAN CREPEAU                 Refer#: NONE
  To: CORIDON HENSHAW               Recvd: NO  
Subj: Crc'S And Ecc'S                Conf: (2) Quik_Bas
In a message to ALL, CORIDON HENSHAW wrote:
CH=> Does anyone know some kind of CRC system in BASIC or a ECC system?   I
    need it to  check the integrity  of my progam  AFTER it is  loaded into
    memory.  I know that a file's  CRC can't be in a file,So what  should I
    do?

        Try using the following sub to calculate a CRC.

defint a-z
sub crc(c,x)
const magic=&h1021
for i=1 to 8
        if c<0 then
                c=(2*c and 65535) xor magic
        else
                c=2*c and 65535
        endif
next
c=c xor (x and 255)
end sub

How to use it to verify a CRC:
- You initialise c to 0
- For every byte you want to include in the CRC, you call CRC(C,byte)
- If, after the last byte has been computed, C<>0, there is a CRC error

To compute a CRC,
- You do the 1st 2 steps above
- You do CRC(C,0) twice
- C contains the CRC you must ADD  at the end of your string of bytes.  You
    must add the MSB first (the first 8 bits), then the LSB

-  You  may  change  the  magic  number  (&h1021),  but  this  one has been
    optimized.
---
 * Origin: INTERACESS Montreal (QC) Canada (514) 528-1415 (1:167/280)
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