BBS: Inland Empire Archive
Date: 07-19-92 (15:55)             Number: 26
From: JEAN CREPEAU                 Refer#: NONE
  To: CURTIS STRATMAN               Recvd: NO  
Subj: Questions                      Conf: (2) Quik_Bas
In a message to ALL, CURTIS STRATMAN wrote:
CS=> I have a few questions I hope some of you can answer.

CS=> 1) Can anybody give me a CRC16 routine? How do you calculate an  octal
    number of a file last changed in seconds from Jan 1, 1970? Does  anyone
    have a quick checksum routine?

        Here is a simple CRC16 subroutine

sub crc(count as long,char as integer)
const magic&=&h11021
for i=1 to 8
        if count and &h10000 then count=count xor magic&
count=count xor char
end sub

        You  must  initialize  the  counter  before  using this subroutine.
Usually, you preset  the value to  0 or &hFFFF.  You can replace  the magic
number by  any other  in the  familly &h1xxxx  (since is  a 16-bit CRC). To
compute the CRC:
1. count=0 or count=&hFFFF
2. For each character (8-bit) you read, you CALL CRC (count,char)
3. CALL CRC (count,0)
4. CALL CRC (count,0) (yes, a second time)
5. the CRC value is count or (count xor &hFFFF)
        Store the CRC at the end of the data stream starting by
        the MSB=count\&h100 and then by the LSB=count and &hFF

        Depeding  on  you  needs,  you  can  preset  the counter to 1's and
reverse all the bits at the end of the computation. The common and easy way
to  do  it  is  to  preset  it  to  0's and take it directly after two NULL
characters sent.

        To check if the data stream is ok:
1. count=0 or count=&hFFFF (must be the the same value as above)
2. For each character including the two CRC characters added at the end
        of the data stream, CALL CRC(count,char)
3. If count=0, the data stream is ok

 * 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